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 and an exception handler.
28 * If the Symfony ClassLoader component is available, a special
29 * class loader is also registered.
31 * @param int $errorReportingLevel The level of error reporting you want
32 * @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
34 public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
36 if (static::$enabled) {
40 static::$enabled = true;
42 if (null !== $errorReportingLevel) {
43 error_reporting($errorReportingLevel);
45 error_reporting(E_ALL);
48 if ('cli' !== PHP_SAPI) {
49 ini_set('display_errors', 0);
50 ExceptionHandler::register();
51 } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
52 // CLI - display errors only if they're not already logged to STDERR
53 ini_set('display_errors', 1);
56 ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
58 ErrorHandler::register()->throwAt(0, true);
61 DebugClassLoader::enable();