@@ 31-46 (lines=16) @@ | ||
28 | return $currentSource; |
|
29 | } |
|
30 | ||
31 | public function set(array &$source, string $path, $value): void |
|
32 | { |
|
33 | $keys = explode($this->delimiter, $path); |
|
34 | ||
35 | $currentSource = &$source; |
|
36 | ||
37 | foreach ($keys as $key) { |
|
38 | if (!array_key_exists($key, $currentSource)) { |
|
39 | $currentSource[$key] = []; |
|
40 | } |
|
41 | ||
42 | $currentSource = &$currentSource[$key]; |
|
43 | } |
|
44 | ||
45 | $currentSource = $value; |
|
46 | } |
|
47 | ||
48 | public function exists(array $source, string $path): bool |
|
49 | { |
|
@@ 59-76 (lines=18) @@ | ||
56 | return true; |
|
57 | } |
|
58 | ||
59 | public function remove(array &$source, string $path): void |
|
60 | { |
|
61 | $keys = explode($this->delimiter, $path); |
|
62 | ||
63 | $lastKey = array_pop($keys); |
|
64 | ||
65 | $currentSource = &$source; |
|
66 | ||
67 | foreach ($keys as $key) { |
|
68 | if (!array_key_exists($key, $currentSource)) { |
|
69 | return; |
|
70 | } |
|
71 | ||
72 | $currentSource = &$currentSource[$key]; |
|
73 | } |
|
74 | ||
75 | unset($currentSource[$lastKey]); |
|
76 | } |
|
77 | } |
|
78 |