annotate vendor/symfony/debug/Debug.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Debug;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Registers all the debug tools.
Chris@0 16 *
Chris@0 17 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 18 */
Chris@0 19 class Debug
Chris@0 20 {
Chris@0 21 private static $enabled = false;
Chris@0 22
Chris@0 23 /**
Chris@0 24 * Enables the debug tools.
Chris@0 25 *
Chris@16 26 * This method registers an error handler, an exception handler and a special class loader.
Chris@0 27 *
Chris@0 28 * @param int $errorReportingLevel The level of error reporting you want
Chris@0 29 * @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
Chris@0 30 */
Chris@0 31 public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
Chris@0 32 {
Chris@0 33 if (static::$enabled) {
Chris@0 34 return;
Chris@0 35 }
Chris@0 36
Chris@0 37 static::$enabled = true;
Chris@0 38
Chris@0 39 if (null !== $errorReportingLevel) {
Chris@0 40 error_reporting($errorReportingLevel);
Chris@0 41 } else {
Chris@0 42 error_reporting(E_ALL);
Chris@0 43 }
Chris@0 44
Chris@17 45 if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
Chris@0 46 ini_set('display_errors', 0);
Chris@0 47 ExceptionHandler::register();
Chris@17 48 } elseif ($displayErrors && (!filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) || ini_get('error_log'))) {
Chris@0 49 // CLI - display errors only if they're not already logged to STDERR
Chris@0 50 ini_set('display_errors', 1);
Chris@0 51 }
Chris@0 52 if ($displayErrors) {
Chris@0 53 ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
Chris@0 54 } else {
Chris@0 55 ErrorHandler::register()->throwAt(0, true);
Chris@0 56 }
Chris@0 57
Chris@0 58 DebugClassLoader::enable();
Chris@0 59 }
Chris@0 60 }