From f946108d6526ceaad9b8340fb58335ed4a93eda6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 22 Aug 2013 05:08:01 +0200 Subject: [PATCH] fixed the format of the request used to render an exception --- UPGRADE-3.0.md | 3 +++ .../Bundle/TwigBundle/Controller/ExceptionController.php | 8 +++----- .../HttpKernel/EventListener/ExceptionListener.php | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 5fe5a5bbaf..df10137624 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -34,6 +34,9 @@ UPGRADE FROM 2.x to 3.0 * `Symfony\Bridge\Monolog\Logger` * `Symfony\Component\HttpKernel\Log\NullLogger` + * The `Symfony\Component\HttpKernel\EventListener\ExceptionListener` now + passes the Request format as the `_format` argument instead of `format`. + ### Routing * Some route settings have been renamed: diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index 3c2d14d03c..5a52791966 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -39,22 +39,20 @@ class ExceptionController * @param Request $request The request * @param FlattenException $exception A FlattenException instance * @param DebugLoggerInterface $logger A DebugLoggerInterface instance - * @param string $format The format to use for rendering (html, xml, ...) + * @param string $_format The format to use for rendering (html, xml, ...) * * @return Response * * @throws \InvalidArgumentException When the exception template does not exist */ - public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html') + public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html') { - $request->setRequestFormat($format); - $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); $code = $exception->getStatusCode(); return new Response($this->twig->render( - $this->findTemplate($request, $format, $code, $this->debug), + $this->findTemplate($request, $_format, $code, $this->debug), array( 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index b404de79a7..ef967db422 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -55,6 +55,10 @@ class ExceptionListener implements EventSubscriberInterface '_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, + '_format' => $request->getRequestFormat(), + // keep for BC -- as $format can be an argument of the controller callable + // see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php + // @deprecated in 2.4, to be removed in 3.0 'format' => $request->getRequestFormat(), );