ErrorHandler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Util;
  12. /**
  13. * Convert PHP errors into exceptions
  14. *
  15. * @author Artem Lopata <biozshock@gmail.com>
  16. */
  17. class ErrorHandler
  18. {
  19. /**
  20. * Error handler
  21. *
  22. * @param int $level Level of the error raised
  23. * @param string $message Error message
  24. * @param string $file Filename that the error was raised in
  25. * @param int $line Line number the error was raised at
  26. *
  27. * @static
  28. * @throws \ErrorException
  29. */
  30. public static function handle($level, $message, $file, $line)
  31. {
  32. // respect error_reporting being disabled
  33. if (!error_reporting()) {
  34. return;
  35. }
  36. if (ini_get('xdebug.scream')) {
  37. $message .= "\n\nWarning: You have xdebug.scream enabled, the warning above may be".
  38. "\na legitimately suppressed error that you were not supposed to see.";
  39. }
  40. throw new \ErrorException($message, 0, $level, $file, $line);
  41. }
  42. /**
  43. * Register error handler
  44. *
  45. * @static
  46. */
  47. public static function register()
  48. {
  49. set_error_handler(array(__CLASS__, 'handle'));
  50. }
  51. }