extract method
This commit is contained in:
parent
bcd7ab1eae
commit
6af28015d4
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\HttpKernel\EventListener;
|
namespace Symfony\Component\HttpKernel\EventListener;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
@ -51,15 +52,7 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
|
$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
|
||||||
|
|
||||||
$attributes = array(
|
$request = $this->duplicateRequest($exception, $request);
|
||||||
'_controller' => $this->controller,
|
|
||||||
'exception' => FlattenException::create($exception),
|
|
||||||
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
|
||||||
'format' => $request->getRequestFormat(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$request = $request->duplicate(null, null, $attributes);
|
|
||||||
$request->setMethod('GET');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
||||||
@ -106,4 +99,26 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
error_log($message);
|
error_log($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones the request for the exception.
|
||||||
|
*
|
||||||
|
* @param \Exception $exception The thrown exception.
|
||||||
|
* @param Request $request The original request.
|
||||||
|
*
|
||||||
|
* @return Request $request The cloned request.
|
||||||
|
*/
|
||||||
|
protected function duplicateRequest(\Exception $exception, Request $request)
|
||||||
|
{
|
||||||
|
$attributes = array(
|
||||||
|
'_controller' => $this->controller,
|
||||||
|
'exception' => FlattenException::create($exception),
|
||||||
|
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
||||||
|
'format' => $request->getRequestFormat(),
|
||||||
|
);
|
||||||
|
$request = $request->duplicate(null, null, $attributes);
|
||||||
|
$request->setMethod('GET');
|
||||||
|
|
||||||
|
return $request;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user