Debug.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Debug;
  11. use Symfony\Component\ClassLoader\DebugClassLoader;
  12. /**
  13. * Registers all the debug tools.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class Debug
  18. {
  19. private static $enabled = false;
  20. /**
  21. * Enables the debug tools.
  22. *
  23. * This method registers an error handler and an exception handler.
  24. *
  25. * If the Symfony ClassLoader component is available, a special
  26. * class loader is also registered.
  27. *
  28. * @param integer $errorReportingLevel The level of error reporting you want
  29. * @param Boolean $displayErrors Whether to display errors (for development) or just log them (for production)
  30. */
  31. public static function enable($errorReportingLevel = null, $displayErrors = true)
  32. {
  33. if (static::$enabled) {
  34. return;
  35. }
  36. static::$enabled = true;
  37. error_reporting(-1);
  38. ErrorHandler::register($errorReportingLevel, $displayErrors);
  39. if ('cli' !== php_sapi_name()) {
  40. ExceptionHandler::register();
  41. // CLI - display errors only if they're not already logged to STDERR
  42. } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
  43. ini_set('display_errors', 1);
  44. }
  45. if (class_exists('Symfony\Component\ClassLoader\DebugClassLoader')) {
  46. DebugClassLoader::enable();
  47. }
  48. }
  49. }