1 | <?php declare(strict_types = 1); |
||
16 | abstract class ServiceRegistry implements ServiceRegistryContract |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Array of callable definitions. |
||
21 | * |
||
22 | * @var Invokable[] |
||
23 | */ |
||
24 | private $callableDefinitions = []; |
||
25 | |||
26 | /** |
||
27 | * Array of class definitions. |
||
28 | * |
||
29 | * @var string[] |
||
30 | */ |
||
31 | private $classDefinitions = []; |
||
32 | |||
33 | /** |
||
34 | * Array of resolved instances. |
||
35 | * |
||
36 | * @var object[] |
||
37 | */ |
||
38 | private $instances = []; |
||
39 | |||
40 | /** |
||
41 | * Array of container service identifiers. |
||
42 | * |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $keys = []; |
||
46 | |||
47 | /** |
||
48 | * Array of instances identifiers marked as shared. |
||
49 | * Such instances will be instantiated once and returned on consecutive gets. |
||
50 | * |
||
51 | * @var bool[] |
||
52 | */ |
||
53 | private $shared = []; |
||
54 | |||
55 | /** |
||
56 | * @inheritDoc |
||
57 | */ |
||
58 | 4 | public function addDecorator(string $id, $decorator) |
|
69 | |||
70 | /** |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | 4 | public function addInflection(string $id, string $method, array $arguments = []) |
|
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | 8 | public function bindClass(string $id, string $class, $shared = false) |
|
90 | |||
91 | /** |
||
92 | * @inheritDoc |
||
93 | */ |
||
94 | 12 | public function bindFactory(string $id, $callable, $shared = false) |
|
105 | |||
106 | /** |
||
107 | * @inheritDoc |
||
108 | */ |
||
109 | 5 | public function bindInstance(string $id, $instance) |
|
118 | |||
119 | /** |
||
120 | * @param string $id |
||
121 | * @return null|Invokable |
||
122 | */ |
||
123 | 30 | protected function callableDefinition(string $id) |
|
127 | |||
128 | /** |
||
129 | * @param string $id |
||
130 | * @return null|string |
||
131 | */ |
||
132 | 23 | protected function classDefinition(string $id) |
|
136 | |||
137 | /** |
||
138 | * @return ServiceDecoratorContract |
||
139 | */ |
||
140 | abstract protected function decorator(): ServiceDecoratorContract; |
||
141 | |||
142 | /** |
||
143 | * @return ServiceInflectorContract |
||
144 | */ |
||
145 | abstract protected function inflector(): ServiceInflectorContract; |
||
146 | |||
147 | /** |
||
148 | * @param $id |
||
149 | * @return null|object |
||
150 | */ |
||
151 | 34 | protected function instance(string $id) |
|
155 | |||
156 | /** |
||
157 | * Verifies that provided callable can be called by service container. |
||
158 | * |
||
159 | * @param Invokable $reflectedCallable |
||
160 | * @return bool |
||
161 | */ |
||
162 | 12 | protected function isResolvableCallable(Invokable $reflectedCallable): bool |
|
171 | |||
172 | /** |
||
173 | * Check if container can resolve the service with subject identifier. |
||
174 | * |
||
175 | * @param string $id |
||
176 | * @return bool |
||
177 | */ |
||
178 | 40 | protected function isResolvableService(string $id): bool |
|
182 | |||
183 | /** |
||
184 | * @param string $id |
||
185 | * @return bool |
||
186 | */ |
||
187 | 25 | protected function isShared(string $id): bool |
|
191 | |||
192 | /** |
||
193 | * Normalize key to use across container. |
||
194 | * |
||
195 | * @param string $id |
||
196 | * @return string |
||
197 | */ |
||
198 | 38 | protected function normalize(string $id): string |
|
202 | |||
203 | /** |
||
204 | * Check if subject service is an object instance. |
||
205 | * |
||
206 | * @param mixed $service |
||
207 | * @return bool |
||
208 | */ |
||
209 | 5 | private function isConcrete($service): bool |
|
213 | |||
214 | /** |
||
215 | * Registers binding. |
||
216 | * After this method call binding can be resolved by container. |
||
217 | * |
||
218 | * @param string $id |
||
219 | * @param bool $shared |
||
220 | * @param Closure $registrationCallback |
||
221 | * @return void |
||
222 | */ |
||
223 | 23 | private function register(string $id, bool $shared, Closure $registrationCallback) |
|
241 | |||
242 | /** |
||
243 | * Validate service identifier. Throw an Exception in case of invalid value. |
||
244 | * |
||
245 | * @param string $id |
||
246 | * @return void |
||
247 | * @throws InvalidArgumentException |
||
248 | */ |
||
249 | 23 | private function validateId(string $id) |
|
257 | |||
258 | } |