| @@ 12-51 (lines=40) @@ | ||
| 9 | use Psr\Http\Message\ServerRequestInterface; |
|
| 10 | use Psr\Http\Server\MiddlewareInterface; |
|
| 11 | ||
| 12 | final class LazyMiddlewareAdapter |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var ContainerInterface |
|
| 16 | */ |
|
| 17 | private $container; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @var string |
|
| 21 | */ |
|
| 22 | private $serviceId; |
|
| 23 | ||
| 24 | public function __construct(ContainerInterface $container, string $serviceId) |
|
| 25 | { |
|
| 26 | $this->container = $container; |
|
| 27 | $this->serviceId = $serviceId; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke( |
|
| 31 | ServerRequestInterface $request, |
|
| 32 | ResponseInterface $response, |
|
| 33 | callable $next |
|
| 34 | ): ResponseInterface { |
|
| 35 | /** @var MiddlewareInterface $middleware */ |
|
| 36 | $middleware = $this->container->get($this->serviceId); |
|
| 37 | ||
| 38 | return $middleware->process($request, new MiddlewareRequestHandlerAdapter($response, $next)); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 12-46 (lines=35) @@ | ||
| 9 | use Psr\Http\Message\ServerRequestInterface; |
|
| 10 | use Psr\Http\Server\RequestHandlerInterface; |
|
| 11 | ||
| 12 | final class LazyRequestHandlerAdapter |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var ContainerInterface |
|
| 16 | */ |
|
| 17 | private $container; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @var string |
|
| 21 | */ |
|
| 22 | private $serviceId; |
|
| 23 | ||
| 24 | public function __construct(ContainerInterface $container, string $serviceId) |
|
| 25 | { |
|
| 26 | $this->container = $container; |
|
| 27 | $this->serviceId = $serviceId; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke(ServerRequestInterface $request): ResponseInterface |
|
| 31 | { |
|
| 32 | /** @var RequestHandlerInterface $requestHandler */ |
|
| 33 | $requestHandler = $this->container->get($this->serviceId); |
|
| 34 | ||
| 35 | return $requestHandler->handle($request); |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||