|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Konfig |
|
5
|
|
|
* |
|
6
|
|
|
* Yet another simple configuration loader library. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Xeriab Nabil (aka KodeBurner) <[email protected]> |
|
9
|
|
|
* @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT |
|
10
|
|
|
* @link https://xeriab.github.io/projects/konfig |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Exen\Konfig\Exception; |
|
14
|
|
|
|
|
15
|
|
|
class RuntimeException extends \RuntimeException implements ExceptionInterface |
|
16
|
|
|
{ |
|
17
|
|
|
private $parsedFile = null; |
|
18
|
|
|
private $parsedLine = 0; |
|
19
|
|
|
private $snippe = null; |
|
|
|
|
|
|
20
|
|
|
private $rawMessage = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $message The error message |
|
26
|
|
|
* @param int $parsedLine The line where the error occurred |
|
27
|
|
|
* @param int $snippet The snippet of code near the problem |
|
28
|
|
|
* @param string $parsedFile The file name where the error occurred |
|
29
|
|
|
* @param \Exception $previous The previous exception |
|
30
|
|
|
* @codeCoverageIgnore |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
$message, |
|
34
|
|
|
$parsedLine = -1, |
|
35
|
|
|
$snippet = null, |
|
36
|
|
|
$parsedFile = null, |
|
37
|
|
|
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
|
|
|
* Gets the snippet of code near the error. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string The snippet of code |
|
53
|
|
|
* @codeCoverageIgnore |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getSnippet() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->snippet; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sets the snippet of code near the error. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $snippet The code snippet |
|
64
|
|
|
* @return void |
|
65
|
|
|
* @codeCoverageIgnore |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setSnippet($snippet) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->snippet = $snippet; |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->updateRepr(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Gets the filename where the error occurred. |
|
76
|
|
|
* |
|
77
|
|
|
* This method returns null if a string is parsed. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string The filename |
|
80
|
|
|
* @codeCoverageIgnore |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getParsedFile() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->parsedFile; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Sets the filename where the error occurred. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $parsedFile The filename |
|
91
|
|
|
* @codeCoverageIgnore |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setParsedFile($parsedFile = null) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->parsedFile = $parsedFile; |
|
96
|
|
|
|
|
97
|
|
|
$this->updateRepr(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Gets the line where the error occurred. |
|
102
|
|
|
* |
|
103
|
|
|
* @return int The file line |
|
104
|
|
|
* @codeCoverageIgnore |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getParsedLine() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->parsedLine; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Sets the line where the error occurred. |
|
113
|
|
|
* |
|
114
|
|
|
* @param int $parsedLine The file line |
|
115
|
|
|
* @return void |
|
116
|
|
|
* @codeCoverageIgnore |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setParsedLine($parsedLine = 0) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->parsedLine = $parsedLine; |
|
121
|
|
|
|
|
122
|
|
|
$this->updateRepr(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @codeCoverageIgnore |
|
127
|
|
|
*/ |
|
128
|
|
|
private function updateRepr() |
|
129
|
|
|
{ |
|
130
|
|
|
$this->message = $this->rawMessage; |
|
131
|
|
|
|
|
132
|
|
|
$dot = false; |
|
133
|
|
|
|
|
134
|
|
|
if ('.' === substr($this->message, -1)) { |
|
135
|
|
|
$this->message = substr($this->message, 0, -1); |
|
136
|
|
|
$dot = true; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (null !== $this->parsedFile) { |
|
140
|
|
|
$this->message .= sprintf( |
|
141
|
|
|
' in %s', |
|
142
|
|
|
json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if ($this->parsedLine >= 0) { |
|
147
|
|
|
$this->message .= sprintf(' at line %d', $this->parsedLine); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if ($this->snippet) { |
|
|
|
|
|
|
151
|
|
|
$this->message .= sprintf(' (near "%s")', $this->snippet); |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if ($dot) { |
|
155
|
|
|
$this->message .= '.'; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
// END OF ./src/Exception/RuntimeException.php FILE |
|
161
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.