merged branch dawehner/exception-clone-request (PR #8716)
This PR was merged into the master branch.
Discussion
----------
extract clone duplication logic in exceptionlistener
Drupal needs potentially to adapt the exception listener to add more information from the original request. (see http://drupal.org/node/2057607) so what about extracing some of the logic into a new method.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
Commits
-------
6af2801
extract method
This commit is contained in:
commit
fd1e61ac70
@ -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