| 1 |
<?php |
| 2 |
|
| 3 |
class PHPParser_Error extends RuntimeException |
| 4 |
{ |
| 5 |
protected $rawMessage; |
| 6 |
protected $rawLine; |
| 7 |
|
| 8 |
/** |
| 9 |
* Creates an Exception signifying a parse error. |
| 10 |
* |
| 11 |
* @param string $message Error message |
| 12 |
* @param int $line Error line in PHP file |
| 13 |
*/ |
| 14 |
public function __construct($message, $line = -1) { |
| 15 |
$this->rawMessage = (string) $message; |
| 16 |
$this->rawLine = (int) $line; |
| 17 |
$this->updateMessage(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Gets the error message |
| 22 |
* |
| 23 |
* @return string Error message |
| 24 |
*/ |
| 25 |
public function getRawMessage() { |
| 26 |
return $this->rawMessage; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Sets the line of the PHP file the error occurred in. |
| 31 |
* |
| 32 |
* @param string $message Error message |
| 33 |
*/ |
| 34 |
public function setRawMessage($message) { |
| 35 |
$this->rawMessage = (string) $message; |
| 36 |
$this->updateMessage(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Gets the error line in the PHP file. |
| 41 |
* |
| 42 |
* @return int Error line in the PHP file |
| 43 |
*/ |
| 44 |
public function getRawLine() { |
| 45 |
return $this->rawLine; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Sets the line of the PHP file the error occurred in. |
| 50 |
* |
| 51 |
* @param int $line Error line in the PHP file |
| 52 |
*/ |
| 53 |
public function setRawLine($line) { |
| 54 |
$this->rawLine = (int) $line; |
| 55 |
$this->updateMessage(); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Updates the exception message after a change to rawMessage or rawLine. |
| 60 |
*/ |
| 61 |
protected function updateMessage() { |
| 62 |
$this->message = $this->rawMessage; |
| 63 |
|
| 64 |
if (-1 === $this->rawLine) { |
| 65 |
$this->message .= ' on unknown line'; |
| 66 |
} else { |
| 67 |
$this->message .= ' on line ' . $this->rawLine; |
| 68 |
} |
| 69 |
} |
| 70 |
} |