[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/debug/Symfony/Component/Debug/ -> Debug.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Debug;
  13  
  14  use Symfony\Component\ClassLoader\DebugClassLoader;
  15  
  16  /**
  17   * Registers all the debug tools.
  18   *
  19   * @author Fabien Potencier <fabien@symfony.com>
  20   */
  21  class Debug
  22  {
  23      private static $enabled = false;
  24  
  25      /**
  26       * Enables the debug tools.
  27       *
  28       * This method registers an error handler and an exception handler.
  29       *
  30       * If the Symfony ClassLoader component is available, a special
  31       * class loader is also registered.
  32       *
  33       * @param int  $errorReportingLevel The level of error reporting you want
  34       * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
  35       */
  36      public static function enable($errorReportingLevel = null, $displayErrors = true)
  37      {
  38          if (static::$enabled) {
  39              return;
  40          }
  41  
  42          static::$enabled = true;
  43  
  44          error_reporting(-1);
  45  
  46          ErrorHandler::register($errorReportingLevel, $displayErrors);
  47          if ('cli' !== PHP_SAPI) {
  48              ExceptionHandler::register();
  49  
  50              if (PHP_VERSION_ID >= 70000) {
  51                  $exceptionHandler = set_exception_handler(function ($throwable) use (&$exceptionHandler) {
  52                      if ($throwable instanceof \Exception) {
  53                          $exception = $throwable;
  54                      } else {
  55                          static $refl = null;
  56  
  57                          if (null === $refl) {
  58                              $refl = array();
  59                              foreach (array('file', 'line', 'trace') as $prop) {
  60                                  $prop = new \ReflectionProperty('Exception', $prop);
  61                                  $prop->setAccessible(true);
  62                                  $refl[] = $prop;
  63                              }
  64                          }
  65                          $exception = new \Exception($throwable->getMessage(), $throwable->getCode());
  66                          foreach ($refl as $prop) {
  67                              $prop->setValue($exception, $throwable->{'get'.$prop->name}());
  68                          }
  69                      }
  70                      $exceptionHandler($exception);
  71                  });
  72              }
  73          // CLI - display errors only if they're not already logged to STDERR
  74          } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
  75              ini_set('display_errors', 1);
  76          }
  77  
  78          if (class_exists('Symfony\Component\ClassLoader\DebugClassLoader')) {
  79              DebugClassLoader::enable();
  80          }
  81      }
  82  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1