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 | 20 | public function set(string $key, $value): self |
|
55 | |||
56 | 20 | public function alias(string $alias, string $key): self { |
|
61 | |||
62 | /** |
||
63 | * Check if a DIC value/object exists. |
||
64 | * |
||
65 | * @param string $key |
||
66 | * @return bool |
||
67 | */ |
||
68 | 20 | public function has($key): bool |
|
80 | |||
81 | /** |
||
82 | * @param string $key |
||
83 | * @return bool |
||
84 | */ |
||
85 | 2 | public function hasInstance($key): bool |
|
93 | |||
94 | /** |
||
95 | * Get the shared instance of a DIC object |
||
96 | * |
||
97 | * @param string $key |
||
98 | * @return mixed |
||
99 | */ |
||
100 | 20 | public function get($key) |
|
138 | |||
139 | /** |
||
140 | * Get a new instance of a DIC object |
||
141 | * |
||
142 | * @param string $key |
||
143 | * @return mixed |
||
144 | */ |
||
145 | 3 | public function getNew($key) |
|
167 | |||
168 | /** |
||
169 | * Destroy a DIC object instance. |
||
170 | * |
||
171 | * Will force a new object to be created on next call. |
||
172 | * |
||
173 | * @param string $key |
||
174 | */ |
||
175 | 1 | public function destroyInstance($key): void |
|
179 | |||
180 | /** |
||
181 | * Destroy all DIC object instances. |
||
182 | * |
||
183 | * Will force new objects to be created on next call. |
||
184 | */ |
||
185 | 1 | public function destroyAllInstances(): void |
|
193 | |||
194 | /** |
||
195 | * Magic method to get or set DIC values. |
||
196 | * |
||
197 | * @param string $name |
||
198 | * @param array $arguments |
||
199 | * @return mixed |
||
200 | */ |
||
201 | 5 | public function __call($name, $arguments) |
|
225 | |||
226 | /** |
||
227 | * Instantiate an object of named class using reflection to recursively to resolve dependencies |
||
228 | * |
||
229 | * @param string $className |
||
230 | * @return mixed |
||
231 | * @throws \ReflectionException |
||
232 | */ |
||
233 | 2 | protected function resolveInstance(string $className) { |
|
242 | |||
243 | /** |
||
244 | * Recursively resolve function parameters using reflection |
||
245 | * |
||
246 | * @param \ReflectionParameter[] |
||
247 | * @return mixed |
||
248 | */ |
||
249 | protected function resolveParameters(array $parameters): array { |
||
265 | } |
||
266 |