Final Class Yiisoft\Router\Middleware\Router
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| process() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $matcher | Yiisoft\ |
|
| $responseFactory | \ |
|
| $middlewareFactory | \ |
|
| $currentRoute | Yiisoft\ |
|
| $eventDispatcher | ?\ |
|
public function __construct(
private readonly UrlMatcherInterface $matcher,
private readonly ResponseFactoryInterface $responseFactory,
MiddlewareFactory $middlewareFactory,
private readonly CurrentRoute $currentRoute,
?EventDispatcherInterface $eventDispatcher = null,
) {
$this->dispatcher = new MiddlewareDispatcher($middlewareFactory, $eventDispatcher);
}
| public \ | ||
| $request | \ |
|
| $handler | \ |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$result = $this->matcher->match($request);
$this->currentRoute->setUri($request->getUri());
if ($result->isMethodFailure()) {
if ($request->getMethod() === Method::OPTIONS) {
return $this->responseFactory
->createResponse(Status::NO_CONTENT)
->withHeader('Allow', implode(', ', $result->methods()));
}
return $this->responseFactory
->createResponse(Status::METHOD_NOT_ALLOWED)
->withHeader('Allow', implode(', ', $result->methods()));
}
if (!$result->isSuccess()) {
return $handler->handle($request);
}
$this->currentRoute->setRouteWithArguments($result->route(), $result->arguments());
return $this->dispatcher
->withMiddlewares($result->route()->getData('enabledMiddlewares'))
->dispatch($request, $handler);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.