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;
15 * Registers all the debug tools.
17 * @author Fabien Potencier <fabien@symfony.com>
21 private static $enabled = false;
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) {
37 static::$enabled = true;
39 if (null !== $errorReportingLevel) {
40 error_reporting($errorReportingLevel);
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 && (!filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) || ini_get('error_log'))) {
49 // CLI - display errors only if they're not already logged to STDERR
50 ini_set('display_errors', 1);
53 ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
55 ErrorHandler::register()->throwAt(0, true);
58 DebugClassLoader::enable();