2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-08-22 21:35:44 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2010-08-29 10:52:55 +01:00
|
|
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
|
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
|
|
|
use Symfony\Component\OutputEscaper\SafeDecorator;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-07 02:07:59 +01:00
|
|
|
* ExceptionController.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
|
|
|
class ExceptionController extends Controller
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2010-08-14 21:03:02 +01:00
|
|
|
* Converts an Exception to a Response.
|
|
|
|
*
|
2010-08-29 10:52:55 +01:00
|
|
|
* @param FlattenException $exception A FlattenException instance
|
|
|
|
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
|
|
|
|
* @param string $format The format to use for rendering (html, xml, ...)
|
|
|
|
* @param Boolean $embedded Whether the rendered Response will be embedded or not
|
2010-08-14 21:03:02 +01:00
|
|
|
*
|
2010-05-06 12:25:53 +01:00
|
|
|
* @throws \InvalidArgumentException When the exception template does not exist
|
|
|
|
*/
|
2010-08-29 10:52:55 +01:00
|
|
|
public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger, $format, $embedded = false)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2010-08-26 13:46:11 +01:00
|
|
|
$this['request']->setRequestFormat($format);
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-08-24 11:52:55 +01:00
|
|
|
$currentContent = '';
|
|
|
|
while (false !== $content = ob_get_clean()) {
|
|
|
|
$currentContent .= $content;
|
|
|
|
}
|
|
|
|
|
2010-08-15 07:35:01 +01:00
|
|
|
$response = $this->render(
|
|
|
|
'FrameworkBundle:Exception:'.($this['kernel']->isDebug() ? 'exception' : 'error'),
|
2010-08-24 11:52:55 +01:00
|
|
|
array(
|
2010-08-29 10:52:55 +01:00
|
|
|
'exception' => new SafeDecorator($exception),
|
|
|
|
'logger' => $logger,
|
2010-08-24 11:52:55 +01:00
|
|
|
'currentContent' => $currentContent,
|
2010-08-28 09:11:57 +01:00
|
|
|
'embedded' => $embedded,
|
2010-08-24 11:52:55 +01:00
|
|
|
)
|
2010-08-15 07:35:01 +01:00
|
|
|
);
|
2010-08-29 10:52:55 +01:00
|
|
|
$response->setStatusCode($exception->getStatusCode());
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
return $response;
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|