No Description

Error.php 1.7KB

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