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

ErrorHandler.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 7.18 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\Debug;
 013   
 014  use Symfony\Component\Debug\Exception\FatalErrorException;
 015  use Symfony\Component\Debug\Exception\ContextErrorException;
 016  use Symfony\Component\Debug\Exception\DummyException;
 017  use Psr\Log\LoggerInterface;
 018   
 019  /**
 020   * ErrorHandler.
 021   *
 022   * @author Fabien Potencier <fabien@symfony.com>
 023   * @author Konstantin Myakshin <koc-dp@yandex.ru>
 024   */
 025  class ErrorHandler
 026  {
 027      const TYPE_DEPRECATION = -100;
 028   
 029      private $levels = array(
 030          E_WARNING           => 'Warning',
 031          E_NOTICE            => 'Notice',
 032          E_USER_ERROR        => 'User Error',
 033          E_USER_WARNING      => 'User Warning',
 034          E_USER_NOTICE       => 'User Notice',
 035          E_STRICT            => 'Runtime Notice',
 036          E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
 037          E_DEPRECATED        => 'Deprecated',
 038          E_USER_DEPRECATED   => 'User Deprecated',
 039          E_ERROR             => 'Error',
 040          E_CORE_ERROR        => 'Core Error',
 041          E_COMPILE_ERROR     => 'Compile Error',
 042          E_PARSE             => 'Parse',
 043      );
 044   
 045      private $level;
 046   
 047      private $reservedMemory;
 048   
 049      private $displayErrors;
 050   
 051      /**
 052       * @var LoggerInterface[] Loggers for channels
 053       */
 054      private static $loggers = array();
 055   
 056      /**
 057       * Registers the error handler.
 058       *
 059       * @param int     $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
 060       * @param bool    $displayErrors Display errors (for dev environment) or just log they (production usage)
 061       *
 062       * @return ErrorHandler The registered error handler
 063       */
 064      public static function register($level = null, $displayErrors = true)
 065      {
 066          $handler = new static();
 067          $handler->setLevel($level);
 068          $handler->setDisplayErrors($displayErrors);
 069   
 070          ini_set('display_errors', 0);
 071          set_error_handler(array($handler, 'handle'));
 072          register_shutdown_function(array($handler, 'handleFatal'));
 073          $handler->reservedMemory = str_repeat('x', 10240);
 074   
 075          return $handler;
 076      }
 077   
 078      public function setLevel($level)
 079      {
 080          $this->level = null === $level ? error_reporting() : $level;
 081      }
 082   
 083      public function setDisplayErrors($displayErrors)
 084      {
 085          $this->displayErrors = $displayErrors;
 086      }
 087   
 088      public static function setLogger(LoggerInterface $logger, $channel = 'deprecation')
 089      {
 090          self::$loggers[$channel] = $logger;
 091      }
 092   
 093      /**
 094       * @throws ContextErrorException When error_reporting returns error
 095       */
 096      public function handle($level, $message, $file = 'unknown', $line = 0, $context = array())
 097      {
 098          if (0 === $this->level) {
 099              return false;
 100          }
 101   
 102          if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) {
 103              if (isset(self::$loggers['deprecation'])) {
 104                  if (version_compare(PHP_VERSION, '5.4', '<')) {
 105                      $stack = array_map(
 106                          function ($row) {
 107                              unset($row['args']);
 108   
 109                              return $row;
 110                          },
 111                          array_slice(debug_backtrace(false), 0, 10)
 112                      );
 113                  } else {
 114                      $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
 115                  }
 116   
 117                  self::$loggers['deprecation']->warning($message, array('type' => self::TYPE_DEPRECATION, 'stack' => $stack));
 118              }
 119   
 120              return true;
 121          }
 122   
 123          if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
 124              // make sure the ContextErrorException class is loaded (https://bugs.php.net/bug.php?id=65322)
 125              if (!class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) {
 126                  require __DIR__.'/Exception/ContextErrorException.php';
 127              }
 128              if (!class_exists('Symfony\Component\Debug\Exception\FlattenException')) {
 129                  require __DIR__.'/Exception/FlattenException.php';
 130              }
 131   
 132              if (PHP_VERSION_ID < 50400 && isset($context['GLOBALS']) && is_array($context)) {
 133                  unset($context['GLOBALS']);
 134              }
 135   
 136              $exception = new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
 137   
 138              // Exceptions thrown from error handlers are sometimes not caught by the exception
 139              // handler, so we invoke it directly (https://bugs.php.net/bug.php?id=54275)
 140              $exceptionHandler = set_exception_handler(function () {});
 141              restore_exception_handler();
 142   
 143              if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
 144                  $exceptionHandler[0]->handle($exception);
 145   
 146                  if (!class_exists('Symfony\Component\Debug\Exception\DummyException')) {
 147                      require __DIR__.'/Exception/DummyException.php';
 148                  }
 149   
 150                  // we must stop the PHP script execution, as the exception has
 151                  // already been dealt with, so, let's throw an exception that
 152                  // will be caught by a dummy exception handler
 153                  set_exception_handler(function (\Exception $e) use ($exceptionHandler) {
 154                      if (!$e instanceof DummyException) {
 155                          // happens if our dummy exception is caught by a
 156                          // catch-all from user code, in which case, let's the
 157                          // current handler handle this "new" exception
 158                          call_user_func($exceptionHandler, $e);
 159                      }
 160                  });
 161   
 162                  throw new DummyException();
 163              }
 164          }
 165   
 166          return false;
 167      }
 168   
 169      public function handleFatal()
 170      {
 171          if (null === $error = error_get_last()) {
 172              return;
 173          }
 174   
 175          $this->reservedMemory = '';
 176          $type = $error['type'];
 177          if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
 178              return;
 179          }
 180   
 181          if (isset(self::$loggers['emergency'])) {
 182              $fatal = array(
 183                  'type' => $type,
 184                  'file' => $error['file'],
 185                  'line' => $error['line'],
 186              );
 187   
 188              self::$loggers['emergency']->emerg($error['message'], $fatal);
 189          }
 190   
 191          if (!$this->displayErrors) {
 192              return;
 193          }
 194   
 195          // get current exception handler
 196          $exceptionHandler = set_exception_handler(function () {});
 197          restore_exception_handler();
 198   
 199          if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
 200              $level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
 201              $message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
 202              $exception = new FatalErrorException($message, 0, $type, $error['file'], $error['line']);
 203              $exceptionHandler[0]->handle($exception);
 204          }
 205      }
 206  }
 207