1 | <?php |
||
15 | class ParseException extends ErrorException |
||
16 | { |
||
17 | private $parsedFile; |
||
18 | private $parsedLine; |
||
19 | private $snippet; |
||
20 | private $rawMessage; |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | * |
||
25 | * @param array $error The error array |
||
26 | */ |
||
27 | public function __construct(array $error) |
||
28 | { |
||
29 | $message = isset($error['message']) ? $error['message'] : 'There was an error parsing the file'; |
||
30 | $code = isset($error['code']) ? $error['code'] : 0; |
||
31 | $severity = isset($error['type']) ? $error['type'] : 1; |
||
32 | $fileName = isset($error['file']) ? $error['file'] : __FILE__; |
||
33 | $lineNo = isset($error['line']) ? $error['line'] : __LINE__; |
||
34 | $exception = isset($error['exception']) ? $error['exception'] : null; |
||
35 | $snippet = isset($error['snippet']) ? $error['snippet'] : null; |
||
36 | // $previous = isset($error['previous']) ? $error['previous'] : null; |
||
37 | |||
38 | $this->parsedFile = $fileName; |
||
39 | $this->parsedLine = $lineNo; |
||
40 | $this->snippet = $snippet; |
||
41 | $this->rawMessage = $message; |
||
42 | |||
43 | $this->updateRepr(); |
||
44 | |||
45 | // parent::__construct( |
||
46 | // $this->message, |
||
47 | // 0, |
||
48 | // $previous |
||
49 | // ); |
||
50 | |||
51 | parent::__construct( |
||
52 | $message, |
||
53 | $code, |
||
54 | $severity, |
||
55 | $fileName, |
||
56 | $lineNo, |
||
57 | $exception |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Gets the snippet of code near the error. |
||
63 | * |
||
64 | * @return string The snippet of code |
||
65 | */ |
||
66 | public function getSnippet() |
||
70 | |||
71 | /** |
||
72 | * Sets the snippet of code near the error. |
||
73 | * |
||
74 | * @param string $snippet The code snippet |
||
75 | */ |
||
76 | public function setSnippet($snippet) |
||
82 | |||
83 | /** |
||
84 | * Gets the filename where the error occurred. |
||
85 | * |
||
86 | * This method returns null if a string is parsed. |
||
87 | * |
||
88 | * @return string The filename |
||
89 | */ |
||
90 | public function getParsedFile() |
||
94 | |||
95 | /** |
||
96 | * Sets the filename where the error occurred. |
||
97 | * |
||
98 | * @param string $parsedFile The filename |
||
99 | */ |
||
100 | public function setParsedFile(string $parsedFile = null) |
||
106 | |||
107 | /** |
||
108 | * Gets the line where the error occurred. |
||
109 | * |
||
110 | * @return int The file line |
||
111 | */ |
||
112 | public function getParsedLine() |
||
116 | |||
117 | /** |
||
118 | * Sets the line where the error occurred. |
||
119 | * |
||
120 | * @param int $parsedLine The file line |
||
121 | */ |
||
122 | public function setParsedLine(int $parsedLine = 0) |
||
128 | |||
129 | private function updateRepr() |
||
159 | } |
||
160 | |||
162 |