comparison vendor/symfony/http-kernel/HttpKernel.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
23 use Symfony\Component\HttpKernel\Event\FinishRequestEvent; 23 use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
24 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 24 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
25 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; 25 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
26 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 26 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
27 use Symfony\Component\HttpKernel\Event\PostResponseEvent; 27 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
28 use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; 28 use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
29 use Symfony\Component\HttpFoundation\Request; 29 use Symfony\Component\HttpFoundation\Request;
30 use Symfony\Component\HttpFoundation\RequestStack; 30 use Symfony\Component\HttpFoundation\RequestStack;
31 use Symfony\Component\HttpFoundation\Response; 31 use Symfony\Component\HttpFoundation\Response;
32 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 32 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
33 33
65 $request->headers->set('X-Php-Ob-Level', ob_get_level()); 65 $request->headers->set('X-Php-Ob-Level', ob_get_level());
66 66
67 try { 67 try {
68 return $this->handleRaw($request, $type); 68 return $this->handleRaw($request, $type);
69 } catch (\Exception $e) { 69 } catch (\Exception $e) {
70 if ($e instanceof ConflictingHeadersException) { 70 if ($e instanceof RequestExceptionInterface) {
71 $e = new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e); 71 $e = new BadRequestHttpException($e->getMessage(), $e);
72 } 72 }
73 if (false === $catch) { 73 if (false === $catch) {
74 $this->finishRequest($request, $type); 74 $this->finishRequest($request, $type);
75 75
76 throw $e; 76 throw $e;
87 { 87 {
88 $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response)); 88 $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response));
89 } 89 }
90 90
91 /** 91 /**
92 * @throws \LogicException If the request stack is empty
93 *
94 * @internal 92 * @internal
95 */ 93 */
96 public function terminateWithException(\Exception $exception) 94 public function terminateWithException(\Exception $exception, Request $request = null)
97 { 95 {
98 if (!$request = $this->requestStack->getMasterRequest()) { 96 if (!$request = $request ?: $this->requestStack->getMasterRequest()) {
99 throw new \LogicException('Request stack is empty', 0, $exception); 97 throw $exception;
100 } 98 }
101 99
102 $response = $this->handleException($exception, $request, self::MASTER_REQUEST); 100 $response = $this->handleException($exception, $request, self::MASTER_REQUEST);
103 101
104 $response->sendHeaders(); 102 $response->sendHeaders();
148 $this->dispatcher->dispatch(KernelEvents::CONTROLLER_ARGUMENTS, $event); 146 $this->dispatcher->dispatch(KernelEvents::CONTROLLER_ARGUMENTS, $event);
149 $controller = $event->getController(); 147 $controller = $event->getController();
150 $arguments = $event->getArguments(); 148 $arguments = $event->getArguments();
151 149
152 // call controller 150 // call controller
153 $response = call_user_func_array($controller, $arguments); 151 $response = \call_user_func_array($controller, $arguments);
154 152
155 // view 153 // view
156 if (!$response instanceof Response) { 154 if (!$response instanceof Response) {
157 $event = new GetResponseForControllerResultEvent($this, $request, $type, $response); 155 $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
158 $this->dispatcher->dispatch(KernelEvents::VIEW, $event); 156 $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
240 238
241 $response = $event->getResponse(); 239 $response = $event->getResponse();
242 240
243 // the developer asked for a specific status code 241 // the developer asked for a specific status code
244 if ($response->headers->has('X-Status-Code')) { 242 if ($response->headers->has('X-Status-Code')) {
243 @trigger_error(sprintf('Using the X-Status-Code header is deprecated since Symfony 3.3 and will be removed in 4.0. Use %s::allowCustomResponseCode() instead.', GetResponseForExceptionEvent::class), E_USER_DEPRECATED);
244
245 $response->setStatusCode($response->headers->get('X-Status-Code')); 245 $response->setStatusCode($response->headers->get('X-Status-Code'));
246 246
247 $response->headers->remove('X-Status-Code'); 247 $response->headers->remove('X-Status-Code');
248 } elseif (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) { 248 } elseif (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
249 // ensure that we actually have an error response 249 // ensure that we actually have an error response
250 if ($e instanceof HttpExceptionInterface) { 250 if ($e instanceof HttpExceptionInterface) {
251 // keep the HTTP status code and headers 251 // keep the HTTP status code and headers
252 $response->setStatusCode($e->getStatusCode()); 252 $response->setStatusCode($e->getStatusCode());
253 $response->headers->add($e->getHeaders()); 253 $response->headers->add($e->getHeaders());