* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\EventListener; use Psr\Log\LoggerInterface; use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * ExceptionListener. * * @author Fabien Potencier */ class ExceptionListener implements EventSubscriberInterface { protected $controller; protected $logger; protected $debug; private $charset; public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null) { $this->controller = $controller; $this->logger = $logger; $this->debug = $debug; $this->charset = $charset; } public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $request = $event->getRequest(); $eventDispatcher = func_num_args() > 2 ? func_get_arg(2) : null; $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine())); $request = $this->duplicateRequest($exception, $request); try { $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false); } catch (\Exception $e) { $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())); $wrapper = $e; while ($prev = $wrapper->getPrevious()) { if ($exception === $wrapper = $prev) { throw $e; } } $prev = new \ReflectionProperty('Exception', 'previous'); $prev->setAccessible(true); $prev->setValue($wrapper, $exception); throw $e; } $event->setResponse($response); if ($this->debug && $eventDispatcher instanceof EventDispatcherInterface) { $cspRemovalListener = function (FilterResponseEvent $event) use (&$cspRemovalListener, $eventDispatcher) { $event->getResponse()->headers->remove('Content-Security-Policy'); $eventDispatcher->removeListener(KernelEvents::RESPONSE, $cspRemovalListener); }; $eventDispatcher->addListener(KernelEvents::RESPONSE, $cspRemovalListener, -128); } } public static function getSubscribedEvents() { return array( KernelEvents::EXCEPTION => array('onKernelException', -128), ); } /** * Logs an exception. * * @param \Exception $exception The \Exception instance * @param string $message The error message to log */ protected function logException(\Exception $exception, $message) { if (null !== $this->logger) { if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) { $this->logger->critical($message, array('exception' => $exception)); } else { $this->logger->error($message, array('exception' => $exception)); } } } /** * 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( 'exception' => $exception = FlattenException::create($exception), '_controller' => $this->controller ?: function () use ($exception) { $handler = new ExceptionHandler($this->debug, $this->charset); return new Response($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders()); }, 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, ); $request = $request->duplicate(null, null, $attributes); $request->setMethod('GET'); return $request; } } __halt_compiler();----SIGNATURE:----JHx8m+Txkc/I6ooHnakHgfS3W9YXWNVbxa8VCkuwv2erRLp70ZkjPYbuePkJBWKkFmg7f/B971fi+He6ZHi4ShNl6xxaVTCh6D8UpBPDQEMPxiU4R+TYCjnZyGKwcZLNCeYRE4jrKWqOAkHcf3rhBNadrzMt3oES/+onexZLJ4nF4fCWppY1ZuQs31O2cI9Bsng9j0Pmm09xzLx0NDlolVhdvaNkQnlaJnwDhqsu96yhTPeC4ko3icNGALbsdT7HDIF9GQq8mr4ok+tO0XomhLCVu1a3SNfqCnH5i3SFu/lTr3c8K37CRriv+gqZKxa5NC2sFekDPYPqz9AwZKXRpdKrrbhAp4JcF3GC0a/GZDyX93IFr97eR+CQhW7zKhhj7btKeQV3RdP2axX9qHBa8Mxk+n3MXj/LmZpoBQAfWMymQ9Y5hNqdyrUgkN7VX9SMiZLb8nL8VZKBYCBpFf4fY1St58W5I/tzN+mac4dPAO3wKJbGB62y3zk+qUK5KHR/+P8oL6pjlrdLjDo4pNocIoSw+DvBK6TpYlO5a+NSa5ArpGP//pT9enoO+XVwql6jAw8hWugl45bHYZrQiBNkdSXGBLtB+LjNHDGTYog8KKBOzqHQUXc1B44RgMRh4LxshGyH+tMsW4/i3ElMOOYt66KNmOU5eQoP+w/IciYEck4=----ATTACHMENT:----NjEzNDU1MzM5MTQ3NDI1MSA1MDMzNTQ1MDI4NjUzMTc5IDg5ODg3NTUwNTY1NzQ2NjY=