. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fisharebest\Webtrees\Validator; use Illuminate\Container\Container; 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 { $route = Validator::attributes($request)->route(); $request_handler = $route->handler; if (is_string($request_handler)) { $request_handler = Container::getInstance()->get($request_handler); } return $request_handler->handle($request); } }