. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Aura\Router\Route; use Illuminate\Container\Container; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use function is_string; /** * Middleware to run a request-handler. */ class RequestHandler implements MiddlewareInterface { /** * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { /** @var Route $route */ $route = $request->getAttribute('route'); $request_handler = $route->handler; if (is_string($request_handler)) { $request_handler = Container::getInstance()->get($request_handler); } assert($request_handler instanceof RequestHandlerInterface); return $request_handler->handle($request); } }