ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ParseException.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
20 {
21  private $parsedFile;
22  private $parsedLine;
23  private $snippet;
24  private $rawMessage;
25 
35  public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null)
36  {
37  $this->parsedFile = $parsedFile;
38  $this->parsedLine = $parsedLine;
39  $this->snippet = $snippet;
40  $this->rawMessage = $message;
41 
42  $this->updateRepr();
43 
44  parent::__construct($this->message, 0, $previous);
45  }
46 
52  public function getSnippet()
53  {
54  return $this->snippet;
55  }
56 
62  public function setSnippet($snippet)
63  {
64  $this->snippet = $snippet;
65 
66  $this->updateRepr();
67  }
68 
76  public function getParsedFile()
77  {
78  return $this->parsedFile;
79  }
80 
86  public function setParsedFile($parsedFile)
87  {
88  $this->parsedFile = $parsedFile;
89 
90  $this->updateRepr();
91  }
92 
98  public function getParsedLine()
99  {
100  return $this->parsedLine;
101  }
102 
108  public function setParsedLine($parsedLine)
109  {
110  $this->parsedLine = $parsedLine;
111 
112  $this->updateRepr();
113  }
114 
115  private function updateRepr()
116  {
117  $this->message = $this->rawMessage;
118 
119  $dot = false;
120  if ('.' === substr($this->message, -1)) {
121  $this->message = substr($this->message, 0, -1);
122  $dot = true;
123  }
124 
125  if (null !== $this->parsedFile) {
126  $this->message .= sprintf(' in %s', json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
127  }
128 
129  if ($this->parsedLine >= 0) {
130  $this->message .= sprintf(' at line %d', $this->parsedLine);
131  }
132 
133  if ($this->snippet) {
134  $this->message .= sprintf(' (near "%s")', $this->snippet);
135  }
136 
137  if ($dot) {
138  $this->message .= '.';
139  }
140  }
141 }
setSnippet($snippet)
Sets the snippet of code near the error.
__construct($message, $parsedLine=-1, $snippet=null, $parsedFile=null, \Exception $previous=null)
Constructor.
setParsedFile($parsedFile)
Sets the filename where the error occurred.
catch(Exception $e) $message
getParsedLine()
Gets the line where the error occurred.
getParsedFile()
Gets the filename where the error occurred.
Exception class thrown when an error occurs during parsing.
getSnippet()
Gets the snippet of code near the error.
setParsedLine($parsedLine)
Sets the line where the error occurred.