Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

DebugHandlersListener.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 6.44 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\Console\ConsoleEvents;
016  use Symfony\Component\Console\Event\ConsoleEvent;
017  use Symfony\Component\Console\Output\ConsoleOutputInterface;
018  use Symfony\Component\Debug\ErrorHandler;
019  use Symfony\Component\Debug\ExceptionHandler;
020  use Symfony\Component\EventDispatcher\Event;
021  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
022  use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
023  use Symfony\Component\HttpKernel\Event\KernelEvent;
024  use Symfony\Component\HttpKernel\KernelEvents;
025   
026  /**
027   * Configures errors and exceptions handlers.
028   *
029   * @author Nicolas Grekas <p@tchwork.com>
030   */
031  class DebugHandlersListener implements EventSubscriberInterface
032  {
033      private $exceptionHandler;
034      private $logger;
035      private $levels;
036      private $throwAt;
037      private $scream;
038      private $fileLinkFormat;
039      private $scope;
040      private $firstCall = true;
041      private $hasTerminatedWithException;
042   
043      /**
044       * @param callable|null                 $exceptionHandler A handler that will be called on Exception
045       * @param LoggerInterface|null          $logger           A PSR-3 logger
046       * @param array|int                     $levels           An array map of E_* to LogLevel::* or an integer bit field of E_* constants
047       * @param int|null                      $throwAt          Thrown errors in a bit field of E_* constants, or null to keep the current value
048       * @param bool                          $scream           Enables/disables screaming mode, where even silenced errors are logged
049       * @param string|FileLinkFormatter|null $fileLinkFormat   The format for links to source files
050       * @param bool                          $scope            Enables/disables scoping mode
051       */
052      public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = \E_ALL, $throwAt = \E_ALL, $scream = true, $fileLinkFormat = null, $scope = true)
053      {
054          $this->exceptionHandler = $exceptionHandler;
055          $this->logger = $logger;
056          $this->levels = null === $levels ? \E_ALL : $levels;
057          $this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? \E_ALL : null));
058          $this->scream = (bool) $scream;
059          $this->fileLinkFormat = $fileLinkFormat;
060          $this->scope = (bool) $scope;
061      }
062   
063      /**
064       * Configures the error handler.
065       */
066      public function configure(Event $event = null)
067      {
068          if ($event instanceof ConsoleEvent && !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
069              return;
070          }
071          if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMasterRequest()) {
072              return;
073          }
074          $this->firstCall = $this->hasTerminatedWithException = false;
075   
076          $handler = set_exception_handler('var_dump');
077          $handler = \is_array($handler) ? $handler[0] : null;
078          restore_exception_handler();
079   
080          if ($this->logger || null !== $this->throwAt) {
081              if ($handler instanceof ErrorHandler) {
082                  if ($this->logger) {
083                      $handler->setDefaultLogger($this->logger, $this->levels);
084                      if (\is_array($this->levels)) {
085                          $levels = 0;
086                          foreach ($this->levels as $type => $log) {
087                              $levels |= $type;
088                          }
089                      } else {
090                          $levels = $this->levels;
091                      }
092                      if ($this->scream) {
093                          $handler->screamAt($levels);
094                      }
095                      if ($this->scope) {
096                          $handler->scopeAt($levels & ~\E_USER_DEPRECATED & ~\E_DEPRECATED);
097                      } else {
098                          $handler->scopeAt(0, true);
099                      }
100                      $this->logger = $this->levels = null;
101                  }
102                  if (null !== $this->throwAt) {
103                      $handler->throwAt($this->throwAt, true);
104                  }
105              }
106          }
107          if (!$this->exceptionHandler) {
108              if ($event instanceof KernelEvent) {
109                  if (method_exists($kernel = $event->getKernel(), 'terminateWithException')) {
110                      $request = $event->getRequest();
111                      $hasRun = &$this->hasTerminatedWithException;
112                      $this->exceptionHandler = static function (\Exception $e) use ($kernel, $request, &$hasRun) {
113                          if ($hasRun) {
114                              throw $e;
115                          }
116                          $hasRun = true;
117                          $kernel->terminateWithException($e, $request);
118                      };
119                  }
120              } elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
121                  $output = $event->getOutput();
122                  if ($output instanceof ConsoleOutputInterface) {
123                      $output = $output->getErrorOutput();
124                  }
125                  $this->exceptionHandler = function ($e) use ($app, $output) {
126                      $app->renderException($e, $output);
127                  };
128              }
129          }
130          if ($this->exceptionHandler) {
131              if ($handler instanceof ErrorHandler) {
132                  $h = $handler->setExceptionHandler('var_dump');
133                  if (\is_array($h) && $h[0] instanceof ExceptionHandler) {
134                      $handler->setExceptionHandler($h);
135                      $handler = $h[0];
136                  } else {
137                      $handler->setExceptionHandler($this->exceptionHandler);
138                  }
139              }
140              if ($handler instanceof ExceptionHandler) {
141                  $handler->setHandler($this->exceptionHandler);
142                  if (null !== $this->fileLinkFormat) {
143                      $handler->setFileLinkFormat($this->fileLinkFormat);
144                  }
145              }
146              $this->exceptionHandler = null;
147          }
148      }
149   
150      public static function getSubscribedEvents()
151      {
152          $events = [KernelEvents::REQUEST => ['configure', 2048]];
153   
154          if (\defined('Symfony\Component\Console\ConsoleEvents::COMMAND')) {
155              $events[ConsoleEvents::COMMAND] = ['configure', 2048];
156          }
157   
158          return $events;
159      }
160  }
161