asdf
This commit is contained in:
parent
48c9c9467d
commit
b12cf019e7
107 changed files with 8372 additions and 186 deletions
34
app/src/Http/InvokerRoutedHandler.php
Normal file
34
app/src/Http/InvokerRoutedHandler.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework\Http;
|
||||
|
||||
use Invoker\InvokerInterface;
|
||||
use Lubian\NoFramework\Exception\InternalServerError;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
final class InvokerRoutedHandler implements RoutedRequestHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvokerInterface $invoker,
|
||||
private string $routeAttributeName = '__route_handler',
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$handler = $request->getAttribute($this->routeAttributeName, false);
|
||||
$vars = $request->getAttributes();
|
||||
$vars['request'] = $request;
|
||||
$response = $this->invoker->call($handler, $vars);
|
||||
if (! $response instanceof ResponseInterface) {
|
||||
throw new InternalServerError('Handler returned invalid response');
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function setRouteAttributeName(string $routeAttributeName = '__route_handler'): void
|
||||
{
|
||||
$this->routeAttributeName = $routeAttributeName;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue