1 | <?php |
||
16 | class Dotted |
||
17 | { |
||
18 | const SEPARATOR = '/[\.]/'; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $values = []; |
||
24 | |||
25 | /** |
||
26 | * @param array $values |
||
27 | */ |
||
28 | public function __construct(array $values = []) |
||
32 | |||
33 | /** |
||
34 | * @param array $values |
||
35 | * |
||
36 | * @return \Fnayou\Dotted |
||
37 | */ |
||
38 | public static function create(array $values = []) |
||
42 | |||
43 | /** |
||
44 | * @param array $values |
||
45 | * |
||
46 | * @return \Fnayou\Dotted |
||
47 | */ |
||
48 | public function setValues(array $values) |
||
54 | |||
55 | /** |
||
56 | * @return array |
||
57 | */ |
||
58 | public function getValues() |
||
62 | |||
63 | /** |
||
64 | * @param string $path |
||
65 | * @param string $default |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function get(string $path, string $default = null) |
||
88 | |||
89 | /** |
||
90 | * @param string $path |
||
91 | * @param array $values |
||
92 | * |
||
93 | * @return \Fnayou\Dotted |
||
94 | */ |
||
95 | public function add(string $path, array $values) |
||
103 | |||
104 | /** |
||
105 | * @param string $path |
||
106 | * @param mixed $value |
||
107 | * |
||
108 | * @throws \InvalidArgumentException |
||
109 | * |
||
110 | * @return \Fnayou\Dotted |
||
111 | */ |
||
112 | public function set(string $path, $value) |
||
140 | |||
141 | /** |
||
142 | * @param string $path |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function has(string $path) |
||
162 | |||
163 | /** |
||
164 | * @return array |
||
165 | */ |
||
166 | public function flatten() |
||
170 | |||
171 | /** |
||
172 | * @param string $path |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | protected function explode(string $path) |
||
180 | |||
181 | /** |
||
182 | * array_merge_recursive does indeed merge arrays, but it converts values with duplicate |
||
183 | * keys to arrays rather than overwriting the value in the first array with the duplicate |
||
184 | * value in the second array, as array_merge does. I.e., with array_merge_recursive, |
||
185 | * this happens (documented behavior):. |
||
186 | * |
||
187 | * array_merge_recursive(array('key' => 'org value'), array('key' => 'new value')); |
||
188 | * => array('key' => array('org value', 'new value')); |
||
189 | * |
||
190 | * arrayMergeRecursiveDistinct does not change the datatypes of the values in the arrays. |
||
191 | * Matching keys' values in the second array overwrite those in the first array, as is the |
||
192 | * case with array_merge, i.e.: |
||
193 | * |
||
194 | * arrayMergeRecursiveDistinct(array('key' => 'org value'), array('key' => 'new value')); |
||
195 | * => array('key' => array('new value')); |
||
196 | * |
||
197 | * Parameters are passed by reference, though only for performance reasons. They're not |
||
198 | * altered by this function. |
||
199 | * |
||
200 | * If key is integer, it will be merged like array_merge do: |
||
201 | * arrayMergeRecursiveDistinct(array(0 => 'org value'), array(0 => 'new value')); |
||
202 | * => array(0 => 'org value', 1 => 'new value'); |
||
203 | * |
||
204 | * @param array $array1 |
||
205 | * @param array $array2 |
||
206 | * |
||
207 | * @return array |
||
208 | * |
||
209 | * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
||
210 | * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
||
211 | * @author Anton Medvedev <anton (at) elfet (dot) ru> |
||
212 | * @author Aymen Fnayou <fnayou (dot) aymen (at) gmail (dot) com> |
||
213 | */ |
||
214 | protected function arrayMergeRecursiveDistinct(array &$array1, array &$array2) |
||
242 | |||
243 | /** |
||
244 | * @param array $array |
||
245 | * @param string|null $parent |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | protected function arrayFlattenRecursive(array $array, string $parent = null) |
||
270 | } |
||
271 |