1 | <?php declare(strict_types=1); |
||
14 | class Dispatcher extends GroupCountBasedDispatcher implements |
||
15 | MiddlewareAwareInterface, |
||
16 | RequestHandlerInterface, |
||
17 | StrategyAwareInterface |
||
18 | { |
||
19 | use MiddlewareAwareTrait; |
||
20 | use StrategyAwareTrait; |
||
21 | |||
22 | /** |
||
23 | * Dispatch the current route. |
||
24 | * |
||
25 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
26 | * |
||
27 | * @return \Psr\Http\Message\ResponseInterface |
||
28 | */ |
||
29 | 30 | public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 30 | public function handle(ServerRequestInterface $request) : ResponseInterface |
|
63 | |||
64 | /** |
||
65 | * Handle dispatching of a found route. |
||
66 | * |
||
67 | * @param \League\Route\Route $route |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 14 | protected function setFoundMiddleware(Route $route) : void |
|
72 | { |
||
73 | 14 | if (is_null($route->getStrategy())) { |
|
74 | $route->setStrategy($this->getStrategy()); |
||
75 | } |
||
76 | |||
77 | // wrap entire dispatch process in exception handler |
||
78 | 14 | $this->prependMiddleware($route->getStrategy()->getExceptionHandler()); |
|
79 | |||
80 | // add group and route specific niddlewares |
||
81 | 14 | if ($group = $route->getParentGroup()) { |
|
82 | 4 | $this->middlewares($group->getMiddlewareStack()); |
|
83 | } |
||
84 | |||
85 | 14 | $this->middlewares($route->getMiddlewareStack()); |
|
86 | |||
87 | // add actual route to end of stack |
||
88 | 14 | $this->middleware($route); |
|
89 | 14 | } |
|
90 | |||
91 | /** |
||
92 | * Handle a not found route. |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | 12 | protected function setNotFoundDecoratorMiddleware() : void |
|
101 | |||
102 | /** |
||
103 | * Handles a not allowed route. |
||
104 | * |
||
105 | * @param array $allowed |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | 4 | protected function setMethodNotAllowedDecoratorMiddleware(array $allowed) : void |
|
117 | } |
||
118 |