@@ -87,78 +87,78 @@ |
||
87 | 87 | return $url; |
88 | 88 | } |
89 | 89 | |
90 | - /** |
|
91 | - * Pull route info for a request with a bad method to decide whether to |
|
92 | - * return a not-found error (default) or a bad-method error, then run |
|
93 | - * the handler for that error, returning the resulting response. |
|
94 | - * |
|
95 | - * Used for cases where an incoming request has an unrecognized method, |
|
96 | - * rather than throwing an exception and not catching it all the way up. |
|
97 | - * |
|
98 | - * @param ServerRequestInterface $request |
|
99 | - * @param ResponseInterface $response |
|
100 | - * @return ResponseInterface |
|
101 | - */ |
|
102 | - protected function processInvalidMethod(ServerRequestInterface $request, ResponseInterface $response) |
|
103 | - { |
|
104 | - $router = $this->container->get('router'); |
|
105 | - if (is_callable([$request->getUri(), 'getBaseUrl']) && is_callable([$router, 'getBaseUrl'])) { |
|
106 | - $router->setBasePath($request->getUri()->getBaseUrl()); |
|
107 | - } |
|
108 | - |
|
109 | - $request = $this->dispatchRouterAndPrepareRoute($request, $router); |
|
110 | - $routeInfo = $request->getAttribute('routeInfo', [RouterInterface::DISPATCH_STATUS => Dispatcher::NOT_FOUND]); |
|
111 | - |
|
112 | - if ($routeInfo[RouterInterface::DISPATCH_STATUS] === Dispatcher::METHOD_NOT_ALLOWED) { |
|
113 | - return $this->handleException( |
|
114 | - new MethodNotAllowedException($request, $response, $routeInfo[RouterInterface::ALLOWED_METHODS]), |
|
115 | - $request, |
|
116 | - $response |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - return $this->handleException(new NotFoundException($request, $response), $request, $response); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Process a request |
|
125 | - * |
|
126 | - * This method traverses the application middleware stack and then returns the |
|
127 | - * resultant Response object. |
|
128 | - * |
|
129 | - * @param ServerRequestInterface $request |
|
130 | - * @param ResponseInterface $response |
|
131 | - * @return ResponseInterface |
|
132 | - * |
|
133 | - * @throws Exception |
|
134 | - * @throws MethodNotAllowedException |
|
135 | - * @throws NotFoundException |
|
136 | - */ |
|
137 | - public function process(ServerRequestInterface $request, ResponseInterface $response) |
|
138 | - { |
|
139 | - // Ensure basePath is set |
|
140 | - $router = $this->container->get('router'); |
|
141 | - if (is_callable([$request->getUri(), 'getBaseUrl']) && is_callable([$router, 'getBaseUrl'])) { |
|
142 | - $router->setBasePath($request->getUri()->getBaseUrl()); |
|
143 | - } |
|
144 | - |
|
145 | - // Dispatch the Router first if the setting for this is on |
|
146 | - if ($this->container->get('settings')['determineRouteBeforeAppMiddleware'] === true) { |
|
147 | - // Dispatch router (note: you won't be able to alter routes after this) |
|
148 | - $request = $this->dispatchRouterAndPrepareRoute($request, $router); |
|
149 | - } |
|
150 | - |
|
151 | - // Traverse middleware stack |
|
152 | - try { |
|
153 | - $response = $this->callMiddlewareStack($request, $response); |
|
154 | - } catch (Exception $e) { |
|
155 | - $response = $this->handleException($e, $request, $response); |
|
156 | - } catch (Throwable $e) { |
|
157 | - $response = $this->handlePhpError($e, $request, $response); |
|
158 | - } |
|
159 | - |
|
160 | - $response = $this->finalize($response); |
|
161 | - |
|
162 | - return $response; |
|
163 | - } |
|
90 | + /** |
|
91 | + * Pull route info for a request with a bad method to decide whether to |
|
92 | + * return a not-found error (default) or a bad-method error, then run |
|
93 | + * the handler for that error, returning the resulting response. |
|
94 | + * |
|
95 | + * Used for cases where an incoming request has an unrecognized method, |
|
96 | + * rather than throwing an exception and not catching it all the way up. |
|
97 | + * |
|
98 | + * @param ServerRequestInterface $request |
|
99 | + * @param ResponseInterface $response |
|
100 | + * @return ResponseInterface |
|
101 | + */ |
|
102 | + protected function processInvalidMethod(ServerRequestInterface $request, ResponseInterface $response) |
|
103 | + { |
|
104 | + $router = $this->container->get('router'); |
|
105 | + if (is_callable([$request->getUri(), 'getBaseUrl']) && is_callable([$router, 'getBaseUrl'])) { |
|
106 | + $router->setBasePath($request->getUri()->getBaseUrl()); |
|
107 | + } |
|
108 | + |
|
109 | + $request = $this->dispatchRouterAndPrepareRoute($request, $router); |
|
110 | + $routeInfo = $request->getAttribute('routeInfo', [RouterInterface::DISPATCH_STATUS => Dispatcher::NOT_FOUND]); |
|
111 | + |
|
112 | + if ($routeInfo[RouterInterface::DISPATCH_STATUS] === Dispatcher::METHOD_NOT_ALLOWED) { |
|
113 | + return $this->handleException( |
|
114 | + new MethodNotAllowedException($request, $response, $routeInfo[RouterInterface::ALLOWED_METHODS]), |
|
115 | + $request, |
|
116 | + $response |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + return $this->handleException(new NotFoundException($request, $response), $request, $response); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Process a request |
|
125 | + * |
|
126 | + * This method traverses the application middleware stack and then returns the |
|
127 | + * resultant Response object. |
|
128 | + * |
|
129 | + * @param ServerRequestInterface $request |
|
130 | + * @param ResponseInterface $response |
|
131 | + * @return ResponseInterface |
|
132 | + * |
|
133 | + * @throws Exception |
|
134 | + * @throws MethodNotAllowedException |
|
135 | + * @throws NotFoundException |
|
136 | + */ |
|
137 | + public function process(ServerRequestInterface $request, ResponseInterface $response) |
|
138 | + { |
|
139 | + // Ensure basePath is set |
|
140 | + $router = $this->container->get('router'); |
|
141 | + if (is_callable([$request->getUri(), 'getBaseUrl']) && is_callable([$router, 'getBaseUrl'])) { |
|
142 | + $router->setBasePath($request->getUri()->getBaseUrl()); |
|
143 | + } |
|
144 | + |
|
145 | + // Dispatch the Router first if the setting for this is on |
|
146 | + if ($this->container->get('settings')['determineRouteBeforeAppMiddleware'] === true) { |
|
147 | + // Dispatch router (note: you won't be able to alter routes after this) |
|
148 | + $request = $this->dispatchRouterAndPrepareRoute($request, $router); |
|
149 | + } |
|
150 | + |
|
151 | + // Traverse middleware stack |
|
152 | + try { |
|
153 | + $response = $this->callMiddlewareStack($request, $response); |
|
154 | + } catch (Exception $e) { |
|
155 | + $response = $this->handleException($e, $request, $response); |
|
156 | + } catch (Throwable $e) { |
|
157 | + $response = $this->handlePhpError($e, $request, $response); |
|
158 | + } |
|
159 | + |
|
160 | + $response = $this->finalize($response); |
|
161 | + |
|
162 | + return $response; |
|
163 | + } |
|
164 | 164 | } |