1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Yaml\Exception;
13:
14: 15: 16: 17: 18: 19: 20:
21: class ParseException extends RuntimeException
22: {
23: private $parsedFile;
24: private $parsedLine;
25: private $snippet;
26: private $rawMessage;
27:
28: 29: 30: 31: 32: 33: 34: 35: 36:
37: public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, Exception $previous = null)
38: {
39: $this->parsedFile = $parsedFile;
40: $this->parsedLine = $parsedLine;
41: $this->snippet = $snippet;
42: $this->rawMessage = $message;
43:
44: $this->updateRepr();
45:
46: parent::__construct($this->message, 0, $previous);
47: }
48:
49: 50: 51: 52: 53:
54: public function getSnippet()
55: {
56: return $this->snippet;
57: }
58:
59: 60: 61: 62: 63:
64: public function setSnippet($snippet)
65: {
66: $this->snippet = $snippet;
67:
68: $this->updateRepr();
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: public function getParsedFile()
79: {
80: return $this->parsedFile;
81: }
82:
83: 84: 85: 86: 87:
88: public function setParsedFile($parsedFile)
89: {
90: $this->parsedFile = $parsedFile;
91:
92: $this->updateRepr();
93: }
94:
95: 96: 97: 98: 99:
100: public function getParsedLine()
101: {
102: return $this->parsedLine;
103: }
104:
105: 106: 107: 108: 109:
110: public function setParsedLine($parsedLine)
111: {
112: $this->parsedLine = $parsedLine;
113:
114: $this->updateRepr();
115: }
116:
117: private function updateRepr()
118: {
119: $this->message = $this->rawMessage;
120:
121: $dot = false;
122: if ('.' === substr($this->message, -1)) {
123: $this->message = substr($this->message, 0, -1);
124: $dot = true;
125: }
126:
127: if (null !== $this->parsedFile) {
128: $this->message .= sprintf(' in %s', json_encode($this->parsedFile));
129: }
130:
131: if ($this->parsedLine >= 0) {
132: $this->message .= sprintf(' at line %d', $this->parsedLine);
133: }
134:
135: if ($this->snippet) {
136: $this->message .= sprintf(' (near "%s")', $this->snippet);
137: }
138:
139: if ($dot) {
140: $this->message .= '.';
141: }
142: }
143: }
144: