eventIdentifier = __CLASS__; $this->pipe = $pipe; $this->responsePrototype = $responsePrototype; $this->setEventManager($eventManager); $this->setEvent($event); } /** * {@inheritDoc} * * @throws RuntimeException */ public function onDispatch(MvcEvent $e) { $routeMatch = $e->getRouteMatch(); $psr7Request = $this->populateRequestParametersFromRoute( $this->loadRequest()->withAttribute(RouteMatch::class, $routeMatch), $routeMatch ); $result = $this->pipe->process($psr7Request, new CallableDelegateDecorator( function () { throw ReachedFinalHandlerException::create(); }, $this->responsePrototype )); $e->setResult($result); return $result; } /** * @return \Laminas\Diactoros\ServerRequest * * @throws RuntimeException */ private function loadRequest() { $request = $this->request; if (! $request instanceof Request) { throw new RuntimeException(sprintf( 'Expected request to be a %s, %s given', Request::class, get_class($request) )); } return Psr7ServerRequest::fromLaminas($request); } /** * @param ServerRequestInterface $request * @param RouteMatch|null $routeMatch * * @return ServerRequestInterface */ private function populateRequestParametersFromRoute(ServerRequestInterface $request, RouteMatch $routeMatch = null) { if (! $routeMatch) { return $request; } foreach ($routeMatch->getParams() as $key => $value) { $request = $request->withAttribute($key, $value); } return $request; } }