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: /**
26: * The wrapped error object
27: *
28: * @var \Error
29: */
30: protected $_error;
31:
32: /**
33: * Wraps the passed Error class
34: *
35: * @param \Error $error the Error object
36: */
37: public function __construct($error)
38: {
39: $this->_error = $error;
40: $this->message = $error->getMessage();
41: $this->code = $error->getCode();
42: $this->file = $error->getFile();
43: $this->line = $error->getLine();
44: $msg = sprintf(
45: '(%s) - %s in %s on %s',
46: get_class($error),
47: $this->message,
48: $this->file ?: 'null',
49: $this->line ?: 'null'
50: );
51: parent::__construct($msg, $this->code, $error->getPrevious());
52: }
53:
54: /**
55: * Returns the wrapped error object
56: *
57: * @return \Error
58: */
59: public function getError()
60: {
61: return $this->_error;
62: }
63: }
64: