Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Debug; Chris@0: Chris@0: /** Chris@0: * Registers all the debug tools. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class Debug Chris@0: { Chris@0: private static $enabled = false; Chris@0: Chris@0: /** Chris@0: * Enables the debug tools. Chris@0: * Chris@16: * This method registers an error handler, an exception handler and a special class loader. Chris@0: * Chris@0: * @param int $errorReportingLevel The level of error reporting you want Chris@0: * @param bool $displayErrors Whether to display errors (for development) or just log them (for production) Chris@0: */ Chris@0: public static function enable($errorReportingLevel = E_ALL, $displayErrors = true) Chris@0: { Chris@0: if (static::$enabled) { Chris@0: return; Chris@0: } Chris@0: Chris@0: static::$enabled = true; Chris@0: Chris@0: if (null !== $errorReportingLevel) { Chris@0: error_reporting($errorReportingLevel); Chris@0: } else { Chris@0: error_reporting(E_ALL); Chris@0: } Chris@0: Chris@17: if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { Chris@0: ini_set('display_errors', 0); Chris@0: ExceptionHandler::register(); Chris@17: } elseif ($displayErrors && (!filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) || ini_get('error_log'))) { Chris@0: // CLI - display errors only if they're not already logged to STDERR Chris@0: ini_set('display_errors', 1); Chris@0: } Chris@0: if ($displayErrors) { Chris@0: ErrorHandler::register(new ErrorHandler(new BufferingLogger())); Chris@0: } else { Chris@0: ErrorHandler::register()->throwAt(0, true); Chris@0: } Chris@0: Chris@0: DebugClassLoader::enable(); Chris@0: } Chris@0: }