Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ExceptionListener.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 4.03 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\HttpKernel\EventListener;
013   
014  use Psr\Log\LoggerInterface;
015  use Symfony\Component\Debug\Exception\FlattenException;
016  use Symfony\Component\HttpFoundation\Request;
017  use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
018  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
019  use Symfony\Component\HttpKernel\KernelEvents;
020  use Symfony\Component\HttpKernel\HttpKernelInterface;
021  use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
022  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
023   
024  /**
025   * ExceptionListener.
026   *
027   * @author Fabien Potencier <fabien@symfony.com>
028   */
029  class ExceptionListener implements EventSubscriberInterface
030  {
031      protected $controller;
032      protected $logger;
033   
034      public function __construct($controller, LoggerInterface $logger = null)
035      {
036          $this->controller = $controller;
037          $this->logger = $logger;
038      }
039   
040      public function onKernelException(GetResponseForExceptionEvent $event)
041      {
042          $exception = $event->getException();
043          $request = $event->getRequest();
044   
045          $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
046   
047          $request = $this->duplicateRequest($exception, $request);
048   
049          try {
050              $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
051          } catch (\Exception $e) {
052              $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()));
053   
054              $wrapper = $e;
055   
056              while ($prev = $wrapper->getPrevious()) {
057                  if ($exception === $wrapper = $prev) {
058                      throw $e;
059                  }
060              }
061   
062              $prev = new \ReflectionProperty('Exception', 'previous');
063              $prev->setAccessible(true);
064              $prev->setValue($wrapper, $exception);
065   
066              throw $e;
067          }
068   
069          $event->setResponse($response);
070      }
071   
072      public static function getSubscribedEvents()
073      {
074          return array(
075              KernelEvents::EXCEPTION => array('onKernelException', -128),
076          );
077      }
078   
079      /**
080       * Logs an exception.
081       *
082       * @param \Exception $exception The \Exception instance
083       * @param string     $message   The error message to log
084       */
085      protected function logException(\Exception $exception, $message)
086      {
087          if (null !== $this->logger) {
088              if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
089                  $this->logger->critical($message, array('exception' => $exception));
090              } else {
091                  $this->logger->error($message, array('exception' => $exception));
092              }
093          }
094      }
095   
096      /**
097       * Clones the request for the exception.
098       *
099       * @param \Exception $exception The thrown exception
100       * @param Request    $request   The original request
101       *
102       * @return Request $request The cloned request
103       */
104      protected function duplicateRequest(\Exception $exception, Request $request)
105      {
106          $attributes = array(
107              '_controller' => $this->controller,
108              'exception' => FlattenException::create($exception),
109              'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
110              // keep for BC -- as $format can be an argument of the controller callable
111              // see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
112              // @deprecated since version 2.4, to be removed in 3.0
113              'format' => $request->getRequestFormat(),
114          );
115          $request = $request->duplicate(null, null, $attributes);
116          $request->setMethod('GET');
117   
118          return $request;
119      }
120  }
121