1 | <?php |
||
36 | trait ReferenceTrait |
||
37 | { |
||
38 | /** |
||
39 | * refernece start chars |
||
40 | * |
||
41 | * @var string |
||
42 | * @access protected |
||
43 | */ |
||
44 | protected $ref_start = '${'; |
||
45 | |||
46 | /** |
||
47 | * reference ending chars |
||
48 | * |
||
49 | * @var string |
||
50 | * @access protected |
||
51 | */ |
||
52 | protected $ref_end = '}'; |
||
53 | |||
54 | /** |
||
55 | * cached pattern to match |
||
56 | * |
||
57 | * @var string |
||
58 | * @access protected |
||
59 | */ |
||
60 | protected $ref_pattern = '~(\$\{((?:(?!\$\{|\}).)+?)\})~'; |
||
61 | |||
62 | /** |
||
63 | * dereference enabled |
||
64 | * |
||
65 | * @var bool |
||
66 | * @access protected |
||
67 | */ |
||
68 | protected $ref_enabled = true; |
||
69 | |||
70 | /** |
||
71 | * {@inheritDoc} |
||
72 | */ |
||
73 | public function setReferencePattern( |
||
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | */ |
||
95 | public function hasReference( |
||
107 | |||
108 | /** |
||
109 | * {@inheritDoc} |
||
110 | */ |
||
111 | public function deReference(/*# string */ $subject) |
||
136 | |||
137 | /** |
||
138 | * {@inheritDoc} |
||
139 | */ |
||
140 | public function deReferenceArray(&$dataArray) |
||
159 | |||
160 | /** |
||
161 | * {@inheritDoc} |
||
162 | * |
||
163 | * @since 2.1.0 |
||
164 | */ |
||
165 | public function enableDeReference(/*# bool */ $flag = true) |
||
170 | |||
171 | /** |
||
172 | * Check dereferenced value |
||
173 | * |
||
174 | * @param mixed $value |
||
175 | * @param string $subject the subject to dereference |
||
176 | * @param string $reference the matched whole reference |
||
177 | * @return mixed |
||
178 | * @throws RuntimeException if $subject malformed, like mix string & array |
||
179 | * @access protected |
||
180 | */ |
||
181 | protected function checkValue( |
||
203 | |||
204 | /** |
||
205 | * Resolve the reference $name |
||
206 | * |
||
207 | * @param string $name |
||
208 | * @return mixed |
||
209 | * @throws RuntimeException if reference unknown |
||
210 | * @access protected |
||
211 | * @since 2.0.8 added localCache support |
||
212 | * @since 2.0.13 removed localCache support |
||
213 | */ |
||
214 | protected function resolveReference(/*# string */ $name) |
||
225 | |||
226 | /** |
||
227 | * Throw exception if looped |
||
228 | * |
||
229 | * @param int $loop loop counter |
||
230 | * @param string $name reference name |
||
231 | * @throws RuntimeException if loop found |
||
232 | * @access protected |
||
233 | * @since 2.0.6 |
||
234 | */ |
||
235 | protected function checkReferenceLoop( |
||
246 | |||
247 | /** |
||
248 | * Lookup reference |
||
249 | * |
||
250 | * @param string $name |
||
251 | * @return mixed |
||
252 | * @access protected |
||
253 | * @since 2.0.15 removed delegator support, moved to individual library |
||
254 | */ |
||
255 | protected function referenceLookup(/*# string */ $name) |
||
259 | |||
260 | /** |
||
261 | * For unknown reference $name, normally returns NULL |
||
262 | * |
||
263 | * @param string $name |
||
264 | * @return mixed |
||
265 | * @throws \Exception if implementor WANTS TO !! |
||
266 | * @access protected |
||
267 | */ |
||
268 | abstract protected function resolveUnknown(/*# string */ $name); |
||
269 | |||
270 | /** |
||
271 | * The REAL resolving method. return NULL for unknown reference |
||
272 | * |
||
273 | * @param string $name |
||
274 | * @return mixed |
||
275 | * @access protected |
||
276 | */ |
||
277 | abstract protected function getReference(/*# string */ $name); |
||
278 | } |
||
279 |