Error.php 1.7 KB

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