made ExceptionManager independent of the Request
This commit is contained in:
parent
82ff79064a
commit
57db35b93b
@ -28,9 +28,9 @@ class ExceptionController extends Controller
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the exception template does not exist
|
* @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 = '';
|
$currentContent = '';
|
||||||
while (false !== $content = ob_get_clean()) {
|
while (false !== $content = ob_get_clean()) {
|
||||||
|
@ -7,6 +7,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
|||||||
use Symfony\Component\EventDispatcher\Event;
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -53,6 +54,7 @@ class ExceptionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$exception = $event->getParameter('exception');
|
$exception = $event->getParameter('exception');
|
||||||
|
$request = $event->getParameter('request');
|
||||||
|
|
||||||
if (null !== $this->logger) {
|
if (null !== $this->logger) {
|
||||||
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
|
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
|
||||||
@ -65,10 +67,12 @@ class ExceptionListener
|
|||||||
|
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'_controller' => $this->controller,
|
'_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 {
|
try {
|
||||||
$response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
$response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
||||||
|
@ -4,7 +4,6 @@ namespace Symfony\Bundle\FrameworkBundle\Debug;
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
|
|
||||||
@ -25,13 +24,11 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
|||||||
class ExceptionManager
|
class ExceptionManager
|
||||||
{
|
{
|
||||||
protected $exception;
|
protected $exception;
|
||||||
protected $request;
|
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
public function __construct(\Exception $exception, Request $request, DebugLoggerInterface $logger = null)
|
public function __construct(\Exception $exception, DebugLoggerInterface $logger = null)
|
||||||
{
|
{
|
||||||
$this->exception = $exception;
|
$this->exception = $exception;
|
||||||
$this->request = $request;
|
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +37,7 @@ class ExceptionManager
|
|||||||
$managers = array();
|
$managers = array();
|
||||||
$e = $this->exception;
|
$e = $this->exception;
|
||||||
while ($e = $e->getPrevious()) {
|
while ($e = $e->getPrevious()) {
|
||||||
$managers[] = new $this($e, $this->request);
|
$managers[] = new $this($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $managers;
|
return $managers;
|
||||||
@ -77,18 +74,6 @@ class ExceptionManager
|
|||||||
return $errors;
|
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()
|
public function getStatusCode()
|
||||||
{
|
{
|
||||||
return $this->exception instanceof HttpException ? $this->exception->getCode() : 500;
|
return $this->exception instanceof HttpException ? $this->exception->getCode() : 500;
|
||||||
|
Reference in New Issue
Block a user