PHP7ErrorException.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @since 3.1.5
  11. * @license https://opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace Cake\Error;
  14. use Exception;
  15. /**
  16. * Wraps a PHP 7 Error object inside a normal Exception
  17. * so it can be handled correctly by the rest of the
  18. * error handling system
  19. */
  20. class PHP7ErrorException extends Exception
  21. {
  22. /**
  23. * The wrapped error object
  24. *
  25. * @var \Error
  26. */
  27. protected $_error;
  28. /**
  29. * Wraps the passed Error class
  30. *
  31. * @param \Error $error the Error object
  32. */
  33. public function __construct($error)
  34. {
  35. $this->_error = $error;
  36. $this->message = $error->getMessage();
  37. $this->code = $error->getCode();
  38. $this->file = $error->getFile();
  39. $this->line = $error->getLine();
  40. $msg = sprintf(
  41. '(%s) - %s in %s on %s',
  42. get_class($error),
  43. $this->message,
  44. $this->file ?: 'null',
  45. $this->line ?: 'null'
  46. );
  47. parent::__construct($msg, $this->code, $error->getPrevious());
  48. }
  49. /**
  50. * Returns the wrapped error object
  51. *
  52. * @return \Error
  53. */
  54. public function getError()
  55. {
  56. return $this->_error;
  57. }
  58. }