1 | <?php |
||
18 | class Container implements ContainerInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private $dicValues = []; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $aliases = []; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $dicObjects = []; |
||
34 | |||
35 | /** |
||
36 | * Set a DIC value. |
||
37 | * |
||
38 | * Wrap objects provided in a closure for lazy loading. |
||
39 | * |
||
40 | * @param string $key |
||
41 | * @param mixed $value |
||
42 | * @return Container |
||
43 | */ |
||
44 | 21 | public function set(string $key, $value): self |
|
55 | |||
56 | public function unset(string $key): void |
||
63 | |||
64 | 21 | public function alias(string $alias, string $key): self |
|
70 | |||
71 | public function unalias(string $alias): void |
||
75 | |||
76 | /** |
||
77 | * Check if a DIC value/object exists. |
||
78 | * |
||
79 | * @param string $key |
||
80 | * @return bool |
||
81 | */ |
||
82 | 1 | public function has($key): bool |
|
90 | |||
91 | /** |
||
92 | * @param string $key |
||
93 | * @return bool |
||
94 | */ |
||
95 | 2 | public function hasInstance($key): bool |
|
103 | |||
104 | /** |
||
105 | * Get the shared instance of a DIC object |
||
106 | * |
||
107 | * @param string $key |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 21 | public function get($key) |
|
135 | |||
136 | /** |
||
137 | * Get a new instance of a DIC object |
||
138 | * |
||
139 | * @param string $key |
||
140 | * @return mixed |
||
141 | */ |
||
142 | 3 | public function getNew(string $key) |
|
157 | |||
158 | 21 | private function getValueInstance(string $key) |
|
170 | |||
171 | /** |
||
172 | * Destroy a DIC object instance. |
||
173 | * |
||
174 | * Will force a new object to be created on next call. |
||
175 | * |
||
176 | * @param string $key |
||
177 | */ |
||
178 | 1 | public function destroyInstance($key): void |
|
182 | |||
183 | /** |
||
184 | * Destroy all DIC object instances. |
||
185 | * |
||
186 | * Will force new objects to be created on next call. |
||
187 | */ |
||
188 | 1 | public function destroyAllInstances(): void |
|
196 | |||
197 | /** |
||
198 | * Magic method to get or set DIC values. |
||
199 | * |
||
200 | * @param string $name |
||
201 | * @param array $arguments |
||
202 | * @return mixed |
||
203 | */ |
||
204 | 3 | public function __call($name, $arguments) |
|
228 | |||
229 | /** |
||
230 | * Instantiate an object of named class, recursively resolving dependencies |
||
231 | * |
||
232 | * @param string $className Fully qualified class name |
||
233 | * @return mixed |
||
234 | * @throws \ReflectionException |
||
235 | */ |
||
236 | 3 | private function resolveInstance(string $className) |
|
253 | |||
254 | /** |
||
255 | * Recursively resolve function parameters using type hints |
||
256 | * |
||
257 | * @param \ReflectionParameter[] |
||
258 | * @return mixed |
||
259 | */ |
||
260 | private function resolveParameters(array $parameters): array |
||
282 | } |
||
283 |