1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Genesis\Config; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Adam Bisek <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class Container implements \IteratorAggregate |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
private $class; |
15
|
|
|
|
16
|
|
|
/** @var array */ |
17
|
|
|
private $parameters = []; |
18
|
|
|
|
19
|
|
|
private $services = []; |
20
|
|
|
|
21
|
|
|
|
22
|
1 |
|
public function getClass() |
23
|
|
|
{ |
24
|
1 |
|
return $this->class; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
3 |
|
public function setClass($class) |
29
|
|
|
{ |
30
|
3 |
|
$this->class = $class; |
31
|
3 |
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
2 |
|
public function getParameter($name) |
35
|
|
|
{ |
36
|
2 |
|
if (!array_key_exists($name, $this->parameters)) { |
37
|
1 |
|
throw new \Exception("Config key '$name' does not exists."); |
38
|
|
|
} |
39
|
1 |
|
return $this->parameters[$name]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
2 |
|
public function getParameters() |
44
|
|
|
{ |
45
|
2 |
|
return $this->parameters; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
3 |
|
public function setParameter($name, $value) |
50
|
|
|
{ |
51
|
3 |
|
$this->parameters[$name] = $value; |
52
|
3 |
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
3 |
|
public function setParameters($parameters) |
56
|
|
|
{ |
57
|
3 |
|
$this->parameters = $parameters; |
58
|
3 |
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
2 |
|
public function getServices() |
62
|
|
|
{ |
63
|
2 |
|
return $this->services; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
2 |
|
public function getService($name) |
68
|
|
|
{ |
69
|
2 |
|
if (!isset($this->services[$name])) { |
70
|
1 |
|
throw new \Exception("Service '$name' does not exists."); |
71
|
|
|
} |
72
|
1 |
|
return $this->services[$name]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
1 |
|
public function hasService($name) |
77
|
|
|
{ |
78
|
1 |
|
return isset($this->services[$name]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
2 |
|
public function addService($name, $service) |
83
|
|
|
{ |
84
|
2 |
|
$this->services[$name] = $service; |
85
|
2 |
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
1 |
|
public function getIterator() |
89
|
|
|
{ |
90
|
1 |
|
return new \ArrayIterator($this->parameters); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
1 |
|
public function &__get($name) |
95
|
|
|
{ |
96
|
1 |
|
throw new \RuntimeException("Direct getting is not supported. Use setParameter('$name') instead."); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
1 |
|
public function __set($name, $value) |
101
|
|
|
{ |
102
|
1 |
|
throw new \RuntimeException("Direct setting is not supported. Use setParameter('$name', ...) instead."); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |