Skip to content

Commit

Permalink
made ExceptionManager independent of the Request
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 26, 2010
1 parent 82ff790 commit 57db35b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
Expand Up @@ -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()) {
Expand Down
Expand Up @@ -7,6 +7,7 @@
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.
Expand Down Expand Up @@ -53,6 +54,7 @@ public function handle(Event $event)
}

$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()));
Expand All @@ -65,10 +67,12 @@ public function handle(Event $event)

$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);
Expand Down
19 changes: 2 additions & 17 deletions src/Symfony/Bundle/FrameworkBundle/Debug/ExceptionManager.php
Expand Up @@ -4,7 +4,6 @@

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;

Expand All @@ -25,13 +24,11 @@
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;
}

Expand All @@ -40,7 +37,7 @@ public function getLinkedManagers()
$managers = array();
$e = $this->exception;
while ($e = $e->getPrevious()) {
$managers[] = new $this($e, $this->request);
$managers[] = new $this($e);
}

return $managers;
Expand Down Expand Up @@ -77,18 +74,6 @@ public function countErrors()
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;
Expand Down

0 comments on commit 57db35b

Please sign in to comment.