composer package updates
[openemr.git] / vendor / symfony / debug / Debug.php
blob8a2b6c8fe751922114940303db0089a40ab86b4e
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Debug;
14 /**
15 * Registers all the debug tools.
17 * @author Fabien Potencier <fabien@symfony.com>
19 class Debug
21 private static $enabled = false;
23 /**
24 * Enables the debug tools.
26 * This method registers an error handler, an exception handler and a special class loader.
28 * @param int $errorReportingLevel The level of error reporting you want
29 * @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
31 public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
33 if (static::$enabled) {
34 return;
37 static::$enabled = true;
39 if (null !== $errorReportingLevel) {
40 error_reporting($errorReportingLevel);
41 } else {
42 error_reporting(E_ALL);
45 if (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true)) {
46 ini_set('display_errors', 0);
47 ExceptionHandler::register();
48 } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
49 // CLI - display errors only if they're not already logged to STDERR
50 ini_set('display_errors', 1);
52 if ($displayErrors) {
53 ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
54 } else {
55 ErrorHandler::register()->throwAt(0, true);
58 DebugClassLoader::enable();