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 = []) |
|
133 | |||
134 | /** |
||
135 | * @inheritDoc |
||
136 | */ |
||
137 | 24 | public function has($id): bool |
|
141 | |||
142 | /** |
||
143 | * @inheritDoc |
||
144 | */ |
||
145 | 1 | public function isCallable($callable): bool |
|
149 | |||
150 | /** |
||
151 | * Create callable factory for the subject service. |
||
152 | * |
||
153 | * @param string $id |
||
154 | * @param array $arguments |
||
155 | * @return mixed |
||
156 | */ |
||
157 | 34 | protected function instantiateService(string $id, array $arguments) |
|
176 | |||
177 | /** |
||
178 | * @return InvokerContract |
||
179 | */ |
||
180 | 44 | protected function invoker(): InvokerContract |
|
184 | |||
185 | /** |
||
186 | * Check if container can resolve the service with subject identifier. |
||
187 | * |
||
188 | * @param string $id |
||
189 | * @return bool |
||
190 | */ |
||
191 | 40 | protected function isResolvableService(string $id): bool |
|
195 | |||
196 | /** |
||
197 | * @param string $id |
||
198 | * @return bool |
||
199 | */ |
||
200 | 29 | protected function isShared(string $id): bool |
|
204 | |||
205 | /** |
||
206 | * Normalize key to use across container. |
||
207 | * |
||
208 | * @param string $id |
||
209 | * @return string |
||
210 | */ |
||
211 | 38 | protected function normalize(string $id): string |
|
215 | |||
216 | /** |
||
217 | * @param InvokerContract $invoker |
||
218 | * @return void |
||
219 | */ |
||
220 | 44 | protected function setInvoker(InvokerContract $invoker) |
|
224 | |||
225 | /** |
||
226 | * Forbid container cloning. |
||
227 | * |
||
228 | * @codeCoverageIgnore |
||
229 | */ |
||
230 | private function __clone() |
||
233 | |||
234 | /** |
||
235 | * Create callable factory with resolved arguments from callable. |
||
236 | * |
||
237 | * @param Invokable $invokable |
||
238 | * @return Closure |
||
239 | */ |
||
240 | 12 | private function createServiceFactoryFromCallable(Invokable $invokable): Closure |
|
246 | |||
247 | /** |
||
248 | * Create callable factory with resolved arguments from class name. |
||
249 | * |
||
250 | * @param string $class |
||
251 | * @return Closure |
||
252 | * @throws UninstantiableServiceException |
||
253 | */ |
||
254 | 23 | private function createServiceFactoryFromClass(string $class): Closure |
|
274 | |||
275 | } |
||
276 |