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) |
||
126 | |||
127 | /** |
||
128 | * {@inheritDoc} |
||
129 | */ |
||
130 | public function deReferenceArray(&$dataArray) |
||
144 | |||
145 | /** |
||
146 | * Check dereferenced value |
||
147 | * |
||
148 | * @param mixed $value |
||
149 | * @param string $subject |
||
150 | * @param string $reference |
||
151 | * @return mixed |
||
152 | * @throws RuntimeException if $subject malformed, like mix string & array |
||
153 | * @access protected |
||
154 | */ |
||
155 | protected function checkValue( |
||
177 | |||
178 | /** |
||
179 | * Resolve the reference $name |
||
180 | * |
||
181 | * @param string $name |
||
182 | * @param int $loop |
||
183 | * @return mixed |
||
184 | * @throws RuntimeException if loop found or reference unknown |
||
185 | * @access protected |
||
186 | * @since 2.0.6 added cache support |
||
187 | */ |
||
188 | protected function resolveReference(/*# string */ $name, /*# int */ $loop) |
||
221 | |||
222 | /** |
||
223 | * Clear reference cache |
||
224 | * |
||
225 | * @return $this |
||
226 | * @access protected |
||
227 | * @since 2.0.6 added |
||
228 | */ |
||
229 | protected function clearReferenceCache() |
||
230 | { |
||
231 | $this->ref_cache = []; |
||
232 | return $this; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * For unknown reference $name, normally returns NULL |
||
237 | * |
||
238 | * @param string $name |
||
239 | * @return mixed |
||
240 | * @throws \Exception if implementor WANTS TO !! |
||
241 | * @access protected |
||
242 | */ |
||
243 | abstract protected function resolveUnknown(/*# string */ $name); |
||
244 | |||
245 | /** |
||
246 | * The real resolving method. return NULL for unknown reference |
||
247 | * |
||
248 | * @param string $name |
||
249 | * @return mixed |
||
250 | * @access protected |
||
251 | */ |
||
252 | abstract protected function getReference(/*# string */ $name); |
||
253 | } |
||
254 |