1 | <?php |
||
32 | trait ReferenceTrait |
||
33 | { |
||
34 | /** |
||
35 | * refernece start chars |
||
36 | * |
||
37 | * @var string |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $ref_start = '${'; |
||
41 | |||
42 | /** |
||
43 | * reference ending chars |
||
44 | * |
||
45 | * @var string |
||
46 | * @access protected |
||
47 | */ |
||
48 | protected $ref_end = '}'; |
||
49 | |||
50 | /** |
||
51 | * cached pattern to match |
||
52 | * |
||
53 | * @var string |
||
54 | * @access protected |
||
55 | */ |
||
56 | protected $ref_pattern = '~(\$\{((?:(?!\$\{|\}).)+?)\})~'; |
||
57 | |||
58 | /** |
||
59 | * cached references |
||
60 | * |
||
61 | * @var array |
||
62 | * @access protected |
||
63 | * @since 2.0.6 |
||
64 | */ |
||
65 | protected $ref_cache = []; |
||
66 | |||
67 | /** |
||
68 | * {@inheritDoc} |
||
69 | */ |
||
70 | public function setReference( |
||
86 | |||
87 | /** |
||
88 | * {@inheritDoc} |
||
89 | */ |
||
90 | public function hasReference( |
||
102 | |||
103 | /** |
||
104 | * {@inheritDoc} |
||
105 | */ |
||
106 | public function deReference(/*# string */ $subject) |
||
129 | |||
130 | /** |
||
131 | * {@inheritDoc} |
||
132 | */ |
||
133 | public function deReferenceArray(&$dataArray) |
||
147 | |||
148 | /** |
||
149 | * Check dereferenced value |
||
150 | * |
||
151 | * @param mixed $value |
||
152 | * @param string $subject |
||
153 | * @param string $reference |
||
154 | * @return mixed |
||
155 | * @throws RuntimeException if $subject malformed, like mix string & array |
||
156 | * @access protected |
||
157 | */ |
||
158 | protected function checkValue( |
||
180 | |||
181 | /** |
||
182 | * Resolve the reference $name |
||
183 | * |
||
184 | * @param string $name |
||
185 | * @return mixed |
||
186 | * @throws RuntimeException if reference unknown |
||
187 | * @access protected |
||
188 | * @since 2.0.6 added cache support |
||
189 | */ |
||
190 | protected function resolveReference(/*# string */ $name) |
||
215 | |||
216 | /** |
||
217 | * Throw exception if looped |
||
218 | * |
||
219 | * @param int $loop loop counter |
||
220 | * @param string $name reference name |
||
221 | * @throws RuntimeException if loop found |
||
222 | * @access public |
||
223 | */ |
||
224 | protected function checkReferenceLoop( |
||
235 | |||
236 | /** |
||
237 | * Clear reference cache |
||
238 | * |
||
239 | * @return $this |
||
240 | * @access protected |
||
241 | * @since 2.0.6 added |
||
242 | */ |
||
243 | protected function clearReferenceCache() |
||
248 | |||
249 | /** |
||
250 | * For unknown reference $name, normally returns NULL |
||
251 | * |
||
252 | * @param string $name |
||
253 | * @return mixed |
||
254 | * @throws \Exception if implementor WANTS TO !! |
||
255 | * @access protected |
||
256 | */ |
||
257 | abstract protected function resolveUnknown(/*# string */ $name); |
||
258 | |||
259 | /** |
||
260 | * The real resolving method. return NULL for unknown reference |
||
261 | * |
||
262 | * @param string $name |
||
263 | * @return mixed |
||
264 | * @access protected |
||
265 | */ |
||
266 | abstract protected function getReference(/*# string */ $name); |
||
267 | } |
||
268 |