Lines
100.00%
6 / 6
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Route | 100.00% | 6 / 6 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| getInfo | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 5 | **/ | |
| 6 | ||
| 7 | namespace BO\Slim\Middleware; | |
| 8 | ||
| 9 | use BO\Slim\Container; | |
| 10 | use Psr\Http\Message\ResponseInterface; | |
| 11 | use Psr\Http\Message\ServerRequestInterface; | |
| 12 | use Psr\Http\Server\RequestHandlerInterface; | |
| 13 | use Slim\Routing\RouteContext; | |
| 14 | ||
| 15 | class Route | |
| 16 | { | |
| 17 | protected Container $container; | |
| 18 | ||
| 19 | public function __construct(Container $container) | |
| 20 | { | |
| 21 | $this->container = $container; | |
| 22 | } | |
| 23 | ||
| 24 | /** @psalm-api Called by Slim as middleware. */ | |
| 25 | public function getInfo(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface | |
| 26 | { | |
| 27 | $routeInstance = $request->getAttribute(RouteContext::ROUTE); | |
| 28 | if ($routeInstance instanceof \Slim\Routing\Route) { | |
| 29 | $this->container['currentRoute'] = $routeInstance->getName(); | |
| 30 | $this->container['currentRouteParams'] = $routeInstance->getArguments(); | |
| 31 | } | |
| 32 | ||
| 33 | return $next->handle($request); | |
| 34 | } | |
| 35 | } |