1 | <?php declare(strict_types = 1); |
||
21 | abstract class AbstractContainer implements ContainerContract |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Array of callable definitions. |
||
26 | * |
||
27 | * @var Invokable[] |
||
28 | */ |
||
29 | protected $callableDefinitions = []; |
||
30 | |||
31 | /** |
||
32 | * Array of class definitions. |
||
33 | * |
||
34 | * @var string[] |
||
35 | */ |
||
36 | protected $classDefinitions = []; |
||
37 | |||
38 | /** |
||
39 | * Array of resolved instances. |
||
40 | * |
||
41 | * @var object[] |
||
42 | */ |
||
43 | protected $instances = []; |
||
44 | |||
45 | /** |
||
46 | * Array of container service identifiers. |
||
47 | * |
||
48 | * @var string[] |
||
49 | */ |
||
50 | protected $keys = []; |
||
51 | |||
52 | /** |
||
53 | * Array of instances identifiers marked as shared. |
||
54 | * Such instances will be instantiated once and returned on consecutive gets. |
||
55 | * |
||
56 | * @var bool[] |
||
57 | */ |
||
58 | protected $shared = []; |
||
59 | |||
60 | /** |
||
61 | * Array of container service callable factories. |
||
62 | * |
||
63 | * @var Closure[] |
||
64 | */ |
||
65 | private $factories = []; |
||
66 | |||
67 | /** |
||
68 | * @var InvokerContract |
||
69 | */ |
||
70 | private $invoker; |
||
71 | |||
72 | /** |
||
73 | * Array of container service identifiers currently being resolved. |
||
74 | * |
||
75 | * @var string[] |
||
76 | */ |
||
77 | private $resolving = []; |
||
78 | |||
79 | /** |
||
80 | * Container constructor. |
||
81 | * |
||
82 | * @param ArgumentResolverContract|null $resolver |
||
83 | */ |
||
84 | 44 | public function __construct(ArgumentResolverContract $resolver = null) |
|
88 | |||
89 | /** |
||
90 | * @inheritDoc |
||
91 | * @param callable|string $callable Callable to call OR class name to instantiate and invoke. |
||
92 | */ |
||
93 | 12 | public function call($callable, array $arguments = []) |
|
97 | |||
98 | /** |
||
99 | * @inheritDoc |
||
100 | */ |
||
101 | 36 | public function get($id, array $arguments = []) |
|
121 | |||
122 | /** |
||
123 | * @inheritDoc |
||
124 | */ |
||
125 | 24 | public function has($id): bool |
|
129 | |||
130 | /** |
||
131 | * @inheritDoc |
||
132 | */ |
||
133 | 1 | public function isCallable($callable): bool |
|
137 | |||
138 | /** |
||
139 | * Create callable factory for the subject service. |
||
140 | * |
||
141 | * @param string $id |
||
142 | * @param array $arguments |
||
143 | * @return mixed |
||
144 | * @throws NotFoundException |
||
145 | */ |
||
146 | 36 | protected function instantiateService(string $id, array $arguments) |
|
171 | |||
172 | /** |
||
173 | * @return InvokerContract |
||
174 | */ |
||
175 | 44 | protected function invoker(): InvokerContract |
|
179 | |||
180 | /** |
||
181 | * Check if container can resolve the service with subject identifier. |
||
182 | * |
||
183 | * @param string $id |
||
184 | * @return bool |
||
185 | */ |
||
186 | 30 | protected function isResolvableService(string $id): bool |
|
190 | |||
191 | /** |
||
192 | * @param string $id |
||
193 | * @return bool |
||
194 | */ |
||
195 | 29 | protected function isShared(string $id): bool |
|
199 | |||
200 | /** |
||
201 | * Normalize key to use across container. |
||
202 | * |
||
203 | * @param string $id |
||
204 | * @return string |
||
205 | */ |
||
206 | 38 | protected function normalize(string $id): string |
|
210 | |||
211 | /** |
||
212 | * @param string $id |
||
213 | * @return void |
||
214 | */ |
||
215 | 36 | protected function resolved(string $id) |
|
219 | |||
220 | /** |
||
221 | * Detects circular references. |
||
222 | * |
||
223 | * @param string $id |
||
224 | * @return void |
||
225 | * @throws CircularReferenceException |
||
226 | */ |
||
227 | 32 | protected function resolving(string $id) |
|
236 | |||
237 | /** |
||
238 | * @param InvokerContract $invoker |
||
239 | * @return void |
||
240 | */ |
||
241 | 44 | protected function setInvoker(InvokerContract $invoker) |
|
245 | |||
246 | /** |
||
247 | * Forbid container cloning. |
||
248 | * |
||
249 | * @codeCoverageIgnore |
||
250 | */ |
||
251 | private function __clone() |
||
254 | |||
255 | /** |
||
256 | * Create callable factory with resolved arguments from callable. |
||
257 | * |
||
258 | * @param Invokable $invokable |
||
259 | * @return Closure |
||
260 | */ |
||
261 | 12 | private function createServiceFactoryFromCallable(Invokable $invokable): Closure |
|
267 | |||
268 | /** |
||
269 | * Create callable factory with resolved arguments from class name. |
||
270 | * |
||
271 | * @param string $class |
||
272 | * @return Closure |
||
273 | * @throws UninstantiableServiceException |
||
274 | */ |
||
275 | 23 | private function createServiceFactoryFromClass(string $class): Closure |
|
295 | } |
||
296 |