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:
15: use Exception;
16:
17: /**
18: * Wraps a PHP 7 Error object inside a normal Exception
19: * so it can be handled correctly by the rest of the
20: * error handling system
21: */
22: class PHP7ErrorException extends Exception
23: {
24: /**
25: * The wrapped error object
26: *
27: * @var \Error
28: */
29: protected $_error;
30:
31: /**
32: * Wraps the passed Error class
33: *
34: * @param \Error $error the Error object
35: */
36: public function __construct($error)
37: {
38: $this->_error = $error;
39: $this->message = $error->getMessage();
40: $this->code = $error->getCode();
41: $this->file = $error->getFile();
42: $this->line = $error->getLine();
43: $msg = sprintf(
44: '(%s) - %s in %s on %s',
45: get_class($error),
46: $this->message,
47: $this->file ?: 'null',
48: $this->line ?: 'null'
49: );
50: parent::__construct($msg, $this->code, $error->getPrevious());
51: }
52:
53: /**
54: * Returns the wrapped error object
55: *
56: * @return \Error
57: */
58: public function getError()
59: {
60: return $this->_error;
61: }
62: }
63: