made ExceptionManager independent of the Request

This commit is contained in:
Fabien Potencier 2010-08-26 14:46:11 +02:00
parent 82ff79064a
commit 57db35b93b
3 changed files with 10 additions and 21 deletions

View File

@ -28,9 +28,9 @@ class ExceptionController extends Controller
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(ExceptionManager $manager)
public function exceptionAction(ExceptionManager $manager, $format)
{
$this['request']->setRequestFormat($manager->getFormat());
$this['request']->setRequestFormat($format);
$currentContent = '';
while (false !== $content = ob_get_clean()) {

View File

@ -7,6 +7,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
/*
* This file is part of the Symfony framework.
@ -53,6 +54,7 @@ class ExceptionListener
}
$exception = $event->getParameter('exception');
$request = $event->getParameter('request');
if (null !== $this->logger) {
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
@ -65,10 +67,12 @@ class ExceptionListener
$attributes = array(
'_controller' => $this->controller,
'manager' => new $class($exception, $event->getParameter('request'), $logger),
'manager' => new $class($exception, $logger),
// when using CLI, we force the format to be TXT
'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat(),
);
$request = $event->getParameter('request')->duplicate(null, null, $attributes);
$request = $request->duplicate(null, null, $attributes);
try {
$response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);

View File

@ -4,7 +4,6 @@ namespace Symfony\Bundle\FrameworkBundle\Debug;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
@ -25,13 +24,11 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
class ExceptionManager
{
protected $exception;
protected $request;
protected $logger;
public function __construct(\Exception $exception, Request $request, DebugLoggerInterface $logger = null)
public function __construct(\Exception $exception, DebugLoggerInterface $logger = null)
{
$this->exception = $exception;
$this->request = $request;
$this->logger = $logger;
}
@ -40,7 +37,7 @@ class ExceptionManager
$managers = array();
$e = $this->exception;
while ($e = $e->getPrevious()) {
$managers[] = new $this($e, $this->request);
$managers[] = new $this($e);
}
return $managers;
@ -77,18 +74,6 @@ class ExceptionManager
return $errors;
}
public function getFormat()
{
$format = $this->request->getRequestFormat();
// when using CLI, we force the format to be TXT
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
$format = 'txt';
}
return $format;
}
public function getStatusCode()
{
return $this->exception instanceof HttpException ? $this->exception->getCode() : 500;