1 | <?php |
||
61 | class DescendDotNotationPath |
||
62 | { |
||
63 | /** |
||
64 | * descend inside an array, using dot.notation.support, and optionally |
||
65 | * extending the array if the end of the dot.notation.path is missing |
||
66 | * |
||
67 | * @param array &$arr |
||
68 | * the array to dig into |
||
69 | * @param string $index |
||
70 | * the dot.notation.support path to descend |
||
71 | * @param array|callable|string|null $extendingItem |
||
72 | * if we need to extend, what data type do we extend using? |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public static function &intoArray(&$arr, $index, $extendingItem = null) |
||
83 | |||
84 | /** |
||
85 | * descend inside an object, using dot.notation.support, and optionally |
||
86 | * extending the object if the end of the dot.notation.path is missing |
||
87 | * |
||
88 | * @param object $obj |
||
89 | * the object to dig into |
||
90 | * @param string $property |
||
91 | * the dot.notation.support path to descend |
||
92 | * @param array|callable|string|null $extendingItem |
||
93 | * if we need to extend, what data type do we extend using? |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public static function &intoObject($obj, $property, $extendingItem = null) |
||
97 | { |
||
98 | // robustness! |
||
99 | RequireAssignable::check($obj, E4xx_UnsupportedType::class); |
||
100 | RequireStringy::check($property, E4xx_UnsupportedType::class); |
||
101 | if (strlen($property) === 0) { |
||
102 | throw new \InvalidArgumentException("'\$property' cannot be empty string"); |
||
103 | } |
||
104 | |||
105 | $retval =& self::getPathFromRoot($obj, $property, $extendingItem); |
||
106 | return $retval; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * descend inside a container, using dot.notation.support, and optionally |
||
111 | * extending the container if the end of the dot.notation.path is missing |
||
112 | * |
||
113 | * @param mixed &$item |
||
114 | * the container to dig into |
||
115 | * @param string $property |
||
116 | * the dot.notation.support path to descend |
||
117 | * @param array|callable|string|null $extendingItem |
||
118 | * if we need to extend, what data type do we extend using? |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public static function &into(&$item, $property, $extendingItem = null) |
||
134 | |||
135 | /** |
||
136 | * descend inside a variable, using dot.notation.support, and optionally |
||
137 | * extending the variable if the end of the dot.notation.path is missing |
||
138 | * |
||
139 | * @deprecated since 2.2.0 |
||
140 | * @codeCoverageIgnore |
||
141 | * |
||
142 | * @param object|array &$item |
||
143 | * the variable to dig into |
||
144 | * @param string $path |
||
145 | * the dot.notation.support path to descend |
||
146 | * @param array|callable|string|null $extendingItem |
||
147 | * if we need to extend, what data type do we extend using? |
||
148 | * @return mixed |
||
149 | */ |
||
150 | public static function &intoMixed($item, $path, $extendingItem = null) |
||
154 | |||
155 | /** |
||
156 | * descend inside a variable, using dot.notation.support, and optionally |
||
157 | * extending the variable if the end of the dot.notation.path is missing |
||
158 | * |
||
159 | * @param object|array &$item |
||
160 | * the variable to dig into |
||
161 | * @param string $path |
||
162 | * the dot.notation.support path to descend |
||
163 | * @param array|callable|string|null $extendingItem |
||
164 | * if we need to extend, what data type do we extend using? |
||
165 | * @return mixed |
||
166 | */ |
||
167 | public function &__invoke($item, $path, $extendingItem = null) |
||
171 | |||
172 | /** |
||
173 | * get whatever is at the end of the given dot.notation.support path, |
||
174 | * optionally extending the path as required |
||
175 | * |
||
176 | * @param array|object &$root |
||
177 | * where we start from |
||
178 | * @param string $path |
||
179 | * the dot.notation.support path to descend |
||
180 | * @param array|callable|string|null $extendingItem |
||
181 | * if we need to extend, what data type do we extend using? |
||
182 | * @return mixed |
||
183 | */ |
||
184 | private static function &getPathFromRoot(&$root, $path, $extendingItem) |
||
208 | |||
209 | /** |
||
210 | * get a child from part of our container tree, optionally extending |
||
211 | * the container if needed |
||
212 | * |
||
213 | * @param array|object &$container |
||
214 | * the container we want to get the child from |
||
215 | * @param string $part |
||
216 | * the name of the child that we want |
||
217 | * @param array|callable|string|null $extendingItem |
||
218 | * if we need to extend the container, this is what we use to |
||
219 | * do the extension |
||
220 | * @return mixed |
||
221 | */ |
||
222 | private static function &getChildFromPart(&$container, $part, $extendingItem = null) |
||
232 | |||
233 | /** |
||
234 | * get a property from an object, extending the object if the property |
||
235 | * does not exist |
||
236 | * |
||
237 | * @param object $obj |
||
238 | * the object to look inside |
||
239 | * @param string $part |
||
240 | * the name of the property to extract |
||
241 | * @param array|callable|string|null $extendingItem |
||
242 | * if we need to extend, what data type do we extend using? |
||
243 | * @return mixed |
||
244 | */ |
||
245 | private static function &getPartFromObject($obj, $part, $extendingItem = null) |
||
260 | |||
261 | /** |
||
262 | * get an index from an array, extending the array if the index does |
||
263 | * not exist |
||
264 | * |
||
265 | * @param array &$arr |
||
266 | * the array to look inside |
||
267 | * @param string $part |
||
268 | * the index to look up |
||
269 | * @param array|callable|string|null $extendingItem |
||
270 | * if we need to extend, what data type do we extend using? |
||
271 | * @return mixed |
||
272 | */ |
||
273 | private static function &getPartFromArray(&$arr, $part, $extendingItem = null) |
||
287 | |||
288 | /** |
||
289 | * create new extension |
||
290 | * |
||
291 | * @param array|callable|string|null $extendingItem |
||
292 | * what data type do we extend using? |
||
293 | * @return array|object |
||
294 | * the extension that has been created |
||
295 | */ |
||
296 | private static function getExtension($extendingItem) |
||
310 | } |
||
311 |