1 | <?php |
||
7 | abstract class PathAwareJsonListener extends IdleListener { |
||
8 | |||
9 | protected $stopAfter = []; |
||
10 | protected $separator = '/'; |
||
11 | |||
12 | protected $value = []; |
||
13 | |||
14 | protected $indent = -1; |
||
15 | protected $array = [false]; |
||
16 | protected $array_index = [-1]; |
||
17 | protected $lastKey = null; |
||
18 | protected $trace = []; |
||
19 | protected $key = []; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | */ |
||
24 | public function __construct() { |
||
29 | |||
30 | /** |
||
31 | * Implements JsonStreamingParser\Listener::endDocument(). |
||
32 | */ |
||
33 | public function endDocument() { |
||
38 | |||
39 | /** |
||
40 | * Implements JsonStreamingParser\Listener::startObject(). |
||
41 | */ |
||
42 | public function startObject() { |
||
51 | |||
52 | /** |
||
53 | * Implements JsonStreamingParser\Listener::endObject(). |
||
54 | */ |
||
55 | public function endObject() { |
||
59 | |||
60 | /** |
||
61 | * Implements JsonStreamingParser\Listener::startArray(). |
||
62 | */ |
||
63 | public function startArray() { |
||
73 | |||
74 | /** |
||
75 | * Implements JsonStreamingParser\Listener::endArray(). |
||
76 | */ |
||
77 | public function endArray() { |
||
82 | |||
83 | /** |
||
84 | * Implements JsonStreamingParser\Listener::key(). |
||
85 | */ |
||
86 | public function key($key) { |
||
92 | |||
93 | /** |
||
94 | * Implements JsonStreamingParser\Listener::value(). |
||
95 | */ |
||
96 | public function value($value) { |
||
104 | |||
105 | /** |
||
106 | * |
||
107 | */ |
||
108 | protected function touch(array $path) { |
||
127 | |||
128 | /** |
||
129 | * |
||
130 | */ |
||
131 | protected function stop($allTouched) { |
||
134 | |||
135 | /** |
||
136 | * Create a complete key from the trace and current level. |
||
137 | */ |
||
138 | protected function composeKey() { |
||
141 | |||
142 | /** |
||
143 | * Trigger a new key, numeric or associative. |
||
144 | */ |
||
145 | protected function arrayKey() { |
||
151 | |||
152 | /** |
||
153 | * Optional helper to save a scalar value into a non-scalar path. |
||
154 | */ |
||
155 | protected function setValue(array &$container, array $key, $value) { |
||
162 | |||
163 | /** |
||
164 | * Remember a value into the provided value property. |
||
165 | */ |
||
166 | protected function rememberValue(array $path, $value) { |
||
169 | |||
170 | /** |
||
171 | * Return the entire saved value. |
||
172 | */ |
||
173 | public function getValue() { |
||
176 | |||
177 | /** |
||
178 | * Define a list of paths (regexes) that must be completed. Completely stops |
||
179 | * the parser after these. |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | public function stopAfter() { |
||
186 | |||
187 | /** |
||
188 | * Get notified about a new key, value still unknown. |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | abstract public function gotPath(array $path); |
||
193 | |||
194 | /** |
||
195 | * Get notified about a new value, including complete path. |
||
196 | * |
||
197 | * @return void |
||
198 | */ |
||
199 | abstract public function gotValue(array $path, $value); |
||
200 | |||
201 | } |
||
202 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: