fixed the format of the request used to render an exception

This commit is contained in:
Fabien Potencier 2013-08-22 05:08:01 +02:00
parent 2872f839ad
commit f946108d65
3 changed files with 10 additions and 5 deletions

View File

@ -34,6 +34,9 @@ UPGRADE FROM 2.x to 3.0
* `Symfony\Bridge\Monolog\Logger` * `Symfony\Bridge\Monolog\Logger`
* `Symfony\Component\HttpKernel\Log\NullLogger` * `Symfony\Component\HttpKernel\Log\NullLogger`
* The `Symfony\Component\HttpKernel\EventListener\ExceptionListener` now
passes the Request format as the `_format` argument instead of `format`.
### Routing ### Routing
* Some route settings have been renamed: * Some route settings have been renamed:

View File

@ -39,22 +39,20 @@ class ExceptionController
* @param Request $request The request * @param Request $request The request
* @param FlattenException $exception A FlattenException instance * @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface 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 * @return Response
* *
* @throws \InvalidArgumentException When the exception template does not exist * @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)); $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$code = $exception->getStatusCode(); $code = $exception->getStatusCode();
return new Response($this->twig->render( return new Response($this->twig->render(
$this->findTemplate($request, $format, $code, $this->debug), $this->findTemplate($request, $_format, $code, $this->debug),
array( array(
'status_code' => $code, 'status_code' => $code,
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',

View File

@ -55,6 +55,10 @@ class ExceptionListener implements EventSubscriberInterface
'_controller' => $this->controller, '_controller' => $this->controller,
'exception' => FlattenException::create($exception), 'exception' => FlattenException::create($exception),
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, '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(), 'format' => $request->getRequestFormat(),
); );