-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigContainer.php
66 lines (50 loc) · 1.44 KB
/
ConfigContainer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace n3b\Bundle\Util;
class ConfigContainer implements \ArrayAccess
{
private $elements;
public function get($key)
{
$keys = explode('.', $key);
if(isset($this->elements[$keys[0]])) {
if(count($keys) > 1 && $this->elements[$keys[0]] instanceof ConfigContainer)
return $this->elements[$keys[0]]->get(\str_replace($keys[0] . '.',
'', $key));
return $this->elements[$keys[0]];
}
return null;
}
public function offsetExists($offset)
{
return isset($this->elements[$offset]);
}
public function offsetGet($offset)
{
return $this->get[$offset];
}
public function offsetSet($offset, $value)
{
if(!isset($offset)) {
return $this->add($value);
}
return $this->elements[$offset] = $value;
}
public function offsetUnset($offset)
{
if (isset($this->elements[$offset])) {
$removed = $this->elements[$offset];
unset($this->elements[$offset]);
return $removed;
}
return null;
}
public function add($value)
{
$this->elements[] = $value;
return true;
}
public function toArray()
{
return \array_map( function($a) {return $a instanceof ConfigContainer ? $a->toArray() : $a; }, $this->elements);
}
}