1 | <?php |
||
42 | class ParseException extends RuntimeException |
||
43 | { |
||
44 | /** @type null|string $parsedFile The file name where the error occurred */ |
||
45 | protected $parsedFile; |
||
46 | /** @type int $parsedLine The line where the error occurred */ |
||
47 | protected $parsedLine; |
||
48 | /** @type int|null $snippet The snippet of code near the problem */ |
||
49 | protected $snippet; |
||
50 | /** @type string $rawMessage The error message */ |
||
51 | protected $rawMessage; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Constructor |
||
56 | * |
||
57 | * @param string $message The error message |
||
58 | * @param int $parsedLine The line where the error occurred |
||
59 | * @param int $snippet The snippet of code near the problem |
||
60 | * @param string $parsedFile The file name where the error occurred |
||
61 | * @param \Exception $previous The previous exception |
||
62 | * |
||
63 | * @return ParseException |
||
|
|||
64 | */ |
||
65 | public function __construct( |
||
66 | $message, |
||
67 | $parsedLine = -1, |
||
68 | $snippet = null, |
||
69 | $parsedFile = null, |
||
70 | \Exception $previous = null |
||
71 | ) { |
||
72 | $this->parsedFile = $parsedFile; |
||
73 | $this->parsedLine = $parsedLine; |
||
74 | $this->snippet = $snippet; |
||
75 | $this->rawMessage = $message; |
||
76 | |||
77 | $this->updateRepr(); |
||
78 | |||
79 | parent::__construct($this->message, 0, $previous); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Gets the snippet of code near the error |
||
84 | * |
||
85 | * @return string The snippet of code |
||
86 | */ |
||
87 | public function getSnippet() |
||
91 | |||
92 | /** |
||
93 | * Sets the snippet of code near the error |
||
94 | * |
||
95 | * @param string $snippet The code snippet |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function setSnippet($snippet) |
||
100 | { |
||
101 | $this->snippet = $snippet; |
||
102 | |||
103 | $this->updateRepr(); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Gets the filename where the error occurred |
||
108 | * |
||
109 | * This method returns null if a string is parsed. |
||
110 | * |
||
111 | * @return string The filename |
||
112 | */ |
||
113 | public function getParsedFile() |
||
117 | |||
118 | /** |
||
119 | * Sets the filename where the error occurred |
||
120 | * |
||
121 | * @param string $parsedFile The filename |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | public function setParsedFile($parsedFile) |
||
126 | { |
||
127 | $this->parsedFile = $parsedFile; |
||
128 | |||
129 | $this->updateRepr(); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Gets the line where the error occurred |
||
134 | * |
||
135 | * @return int The file line |
||
136 | */ |
||
137 | public function getParsedLine() |
||
141 | |||
142 | /** |
||
143 | * Sets the line where the error occurred |
||
144 | * |
||
145 | * @param int $parsedLine The file line |
||
146 | */ |
||
147 | public function setParsedLine($parsedLine) |
||
153 | |||
154 | /** |
||
155 | * Updates the generated message |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | protected function updateRepr() |
||
188 | } |
||
189 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.