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 | 21 | public function alias(string $alias, string $key): self |
|
62 | |||
63 | /** |
||
64 | * Check if a DIC value/object exists. |
||
65 | * |
||
66 | * @param string $key |
||
67 | * @return bool |
||
68 | */ |
||
69 | 2 | public function has($key): bool |
|
77 | |||
78 | /** |
||
79 | * @param string $key |
||
80 | * @return bool |
||
81 | */ |
||
82 | 2 | public function hasInstance($key): bool |
|
90 | |||
91 | /** |
||
92 | * Get the shared instance of a DIC object |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @return mixed |
||
96 | */ |
||
97 | 21 | public function get($key) |
|
132 | |||
133 | /** |
||
134 | * Get a new instance of a DIC object |
||
135 | * |
||
136 | * @param string $key |
||
137 | * @return mixed |
||
138 | */ |
||
139 | 3 | public function getNew(string $key) |
|
161 | |||
162 | /** |
||
163 | * Destroy a DIC object instance. |
||
164 | * |
||
165 | * Will force a new object to be created on next call. |
||
166 | * |
||
167 | * @param string $key |
||
168 | */ |
||
169 | 1 | public function destroyInstance($key): void |
|
173 | |||
174 | /** |
||
175 | * Destroy all DIC object instances. |
||
176 | * |
||
177 | * Will force new objects to be created on next call. |
||
178 | */ |
||
179 | 1 | public function destroyAllInstances(): void |
|
187 | |||
188 | /** |
||
189 | * Magic method to get or set DIC values. |
||
190 | * |
||
191 | * @param string $name |
||
192 | * @param array $arguments |
||
193 | * @return mixed |
||
194 | */ |
||
195 | 3 | public function __call($name, $arguments) |
|
219 | |||
220 | /** |
||
221 | * Instantiate an object of named class, recursively resolving dependencies |
||
222 | * |
||
223 | * @param string $className Fully qualified class name |
||
224 | * @return mixed |
||
225 | * @throws \ReflectionException |
||
226 | */ |
||
227 | 3 | protected function resolveInstance(string $className) |
|
244 | |||
245 | /** |
||
246 | * Recursively resolve function parameters using type hints |
||
247 | * |
||
248 | * @param \ReflectionParameter[] |
||
249 | * @return mixed |
||
250 | */ |
||
251 | protected function resolveParameters(array $parameters): array |
||
273 | } |
||
274 |