Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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: 01.05.2026, 11:26 - Dateigröße: 4.51 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\EventDispatcher\EventDispatcherInterface;
 017  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 018  use Symfony\Component\HttpFoundation\Request;
 019  use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
 020  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 021  use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 022  use Symfony\Component\HttpKernel\HttpKernelInterface;
 023  use Symfony\Component\HttpKernel\KernelEvents;
 024  use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
 025   
 026  /**
 027   * ExceptionListener.
 028   *
 029   * @author Fabien Potencier <fabien@symfony.com>
 030   */
 031  class ExceptionListener implements EventSubscriberInterface
 032  {
 033      protected $controller;
 034      protected $logger;
 035      protected $debug;
 036   
 037      public function __construct($controller, LoggerInterface $logger = null, $debug = false)
 038      {
 039          $this->controller = $controller;
 040          $this->logger = $logger;
 041          $this->debug = $debug;
 042      }
 043   
 044      public function onKernelException(GetResponseForExceptionEvent $event)
 045      {
 046          $exception = $event->getException();
 047          $request = $event->getRequest();
 048          $eventDispatcher = \func_num_args() > 2 ? func_get_arg(2) : null;
 049   
 050          $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
 051   
 052          $request = $this->duplicateRequest($exception, $request);
 053   
 054          try {
 055              $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
 056          } catch (\Exception $e) {
 057              $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()));
 058   
 059              $prev = $e;
 060              do {
 061                  if ($exception === $wrapper = $prev) {
 062                      throw $e;
 063                  }
 064              } while ($prev = $wrapper->getPrevious());
 065   
 066              $prev = new \ReflectionProperty($wrapper instanceof \Exception ? \Exception::class : \Error::class, 'previous');
 067              $prev->setAccessible(true);
 068              $prev->setValue($wrapper, $exception);
 069   
 070              throw $e;
 071          }
 072   
 073          $event->setResponse($response);
 074   
 075          if ($this->debug && $eventDispatcher instanceof EventDispatcherInterface) {
 076              $cspRemovalListener = function (FilterResponseEvent $event) use (&$cspRemovalListener, $eventDispatcher) {
 077                  $event->getResponse()->headers->remove('Content-Security-Policy');
 078                  $eventDispatcher->removeListener(KernelEvents::RESPONSE, $cspRemovalListener);
 079              };
 080              $eventDispatcher->addListener(KernelEvents::RESPONSE, $cspRemovalListener, -128);
 081          }
 082      }
 083   
 084      public static function getSubscribedEvents()
 085      {
 086          return [
 087              KernelEvents::EXCEPTION => ['onKernelException', -128],
 088          ];
 089      }
 090   
 091      /**
 092       * Logs an exception.
 093       *
 094       * @param \Exception $exception The \Exception instance
 095       * @param string     $message   The error message to log
 096       */
 097      protected function logException(\Exception $exception, $message)
 098      {
 099          if (null !== $this->logger) {
 100              if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
 101                  $this->logger->critical($message, ['exception' => $exception]);
 102              } else {
 103                  $this->logger->error($message, ['exception' => $exception]);
 104              }
 105          }
 106      }
 107   
 108      /**
 109       * Clones the request for the exception.
 110       *
 111       * @param \Exception $exception The thrown exception
 112       * @param Request    $request   The original request
 113       *
 114       * @return Request The cloned request
 115       */
 116      protected function duplicateRequest(\Exception $exception, Request $request)
 117      {
 118          $attributes = [
 119              '_controller' => $this->controller,
 120              'exception' => FlattenException::create($exception),
 121              'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
 122          ];
 123          $request = $request->duplicate(null, null, $attributes);
 124          $request->setMethod('GET');
 125   
 126          return $request;
 127      }
 128  }
 129