diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2021-03-17 11:45:23 +0000 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2021-03-18 10:20:57 +0000 |
| commit | aa7265a1309c2dbfd3d38bdbf2f321f4e79ed1e4 (patch) | |
| tree | 555c8e7fec419768fc18a81099f2ae8596586d91 /app/Http/Middleware/RequestHandler.php | |
| parent | 9e2b8e5da604ba9042fc29aa0ab15a5acb10cd6e (diff) | |
| download | webtrees-aa7265a1309c2dbfd3d38bdbf2f321f4e79ed1e4.tar.gz webtrees-aa7265a1309c2dbfd3d38bdbf2f321f4e79ed1e4.tar.bz2 webtrees-aa7265a1309c2dbfd3d38bdbf2f321f4e79ed1e4.zip | |
Remove deprecated code
Diffstat (limited to 'app/Http/Middleware/RequestHandler.php')
| -rw-r--r-- | app/Http/Middleware/RequestHandler.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/Http/Middleware/RequestHandler.php b/app/Http/Middleware/RequestHandler.php new file mode 100644 index 0000000000..959121d2ee --- /dev/null +++ b/app/Http/Middleware/RequestHandler.php @@ -0,0 +1,58 @@ +<?php + +/** + * webtrees: online genealogy + * Copyright (C) 2021 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +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); + } +} |
