Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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:58 - Dateigröße: 3.78 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\HttpKernel\Log\DebugLoggerInterface;
 016  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 017  use Symfony\Component\HttpKernel\KernelEvents;
 018  use Symfony\Component\HttpKernel\HttpKernelInterface;
 019  use Symfony\Component\HttpKernel\Exception\FlattenException;
 020  use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 021  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 022   
 023  /**
 024   * ExceptionListener.
 025   *
 026   * @author Fabien Potencier <fabien@symfony.com>
 027   */
 028  class ExceptionListener implements EventSubscriberInterface
 029  {
 030      protected $controller;
 031      protected $logger;
 032   
 033      public function __construct($controller, LoggerInterface $logger = null)
 034      {
 035          $this->controller = $controller;
 036          $this->logger = $logger;
 037      }
 038   
 039      public function onKernelException(GetResponseForExceptionEvent $event)
 040      {
 041          static $handling;
 042   
 043          if (true === $handling) {
 044              return false;
 045          }
 046   
 047          $handling = true;
 048   
 049          $exception = $event->getException();
 050          $request = $event->getRequest();
 051   
 052          $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
 053   
 054          $attributes = array(
 055              '_controller' => $this->controller,
 056              'exception'   => FlattenException::create($exception),
 057              'logger'      => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
 058              // keep for BC -- as $format can be an argument of the controller callable
 059              // see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
 060              // @deprecated in 2.4, to be removed in 3.0
 061              'format'      => $request->getRequestFormat(),
 062          );
 063   
 064          $request = $request->duplicate(null, null, $attributes);
 065          $request->setMethod('GET');
 066   
 067          try {
 068              $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
 069          } catch (\Exception $e) {
 070              $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
 071   
 072              // set handling to false otherwise it wont be able to handle further more
 073              $handling = false;
 074   
 075              // re-throw the exception from within HttpKernel as this is a catch-all
 076              return;
 077          }
 078   
 079          $event->setResponse($response);
 080   
 081          $handling = false;
 082      }
 083   
 084      public static function getSubscribedEvents()
 085      {
 086          return array(
 087              KernelEvents::EXCEPTION => array('onKernelException', -128),
 088          );
 089      }
 090   
 091      /**
 092       * Logs an exception.
 093       *
 094       * @param \Exception $exception The original \Exception instance
 095       * @param string     $message   The error message to log
 096       * @param bool       $original  False when the handling of the exception thrown another exception
 097       */
 098      protected function logException(\Exception $exception, $message, $original = true)
 099      {
 100          $isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
 101          $context = array('exception' => $exception);
 102          if (null !== $this->logger) {
 103              if ($isCritical) {
 104                  $this->logger->critical($message, $context);
 105              } else {
 106                  $this->logger->error($message, $context);
 107              }
 108          } elseif (!$original || $isCritical) {
 109              error_log($message);
 110          }
 111      }
 112  }
 113