1 | <?php |
||
9 | class Container |
||
10 | { |
||
11 | |||
12 | const _CONSTRUCT = '__construct'; |
||
13 | |||
14 | /** |
||
15 | * is the config array |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $servicesConfig; |
||
20 | |||
21 | /** |
||
22 | * service storage |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $services; |
||
27 | |||
28 | /** |
||
29 | * reporter |
||
30 | * |
||
31 | * @var stdClass |
||
32 | */ |
||
33 | protected $reporter; |
||
34 | |||
35 | /** |
||
36 | * instanciate |
||
37 | * |
||
38 | * @param array $servicesConfig |
||
39 | */ |
||
40 | 18 | public function __construct(array $servicesConfig) |
|
47 | |||
48 | /** |
||
49 | * init reporter |
||
50 | * |
||
51 | * @return Container |
||
52 | */ |
||
53 | 1 | protected function initReporter(): Container |
|
63 | |||
64 | /** |
||
65 | * returns reporter |
||
66 | * |
||
67 | * @return object |
||
|
|||
68 | */ |
||
69 | 1 | public function getReporter(): stdClass |
|
73 | |||
74 | /** |
||
75 | * return all services's container |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 3 | public function getServices(): array |
|
83 | |||
84 | /** |
||
85 | * return service from classname |
||
86 | * |
||
87 | * @param string $serviceName |
||
88 | * @return object |
||
89 | * @throws Exception |
||
90 | */ |
||
91 | 3 | public function getService(string $serviceName) |
|
100 | |||
101 | /** |
||
102 | * set an object instance for a service name |
||
103 | * this should be used in test to mock a service |
||
104 | * or update an existing service yet instanciated |
||
105 | * |
||
106 | * @param string $serviceName |
||
107 | * @param mixed $inst |
||
108 | * @return Container |
||
109 | * @throws Exception |
||
110 | */ |
||
111 | 3 | public function setService(string $serviceName, $inst): Container |
|
121 | |||
122 | /** |
||
123 | * load service from config service |
||
124 | * |
||
125 | * @return Container |
||
126 | * @throws Exception |
||
127 | */ |
||
128 | 2 | protected function load(): Container |
|
138 | |||
139 | /** |
||
140 | * create a service and append in service containter |
||
141 | * |
||
142 | * @param string $serviceName |
||
143 | * @param array $serviceParams |
||
144 | * @return Container |
||
145 | */ |
||
146 | 1 | protected function create(string $serviceName, array $serviceParams): Container |
|
152 | |||
153 | /** |
||
154 | * create core service |
||
155 | * |
||
156 | * @param string $serviceName |
||
157 | * @param array $serviceParams |
||
158 | * @return Container |
||
159 | */ |
||
160 | 1 | protected function createCoreService(string $serviceName, array $serviceParams): Container |
|
184 | |||
185 | /** |
||
186 | * create dependent services |
||
187 | * |
||
188 | * @param array $serviceParams |
||
189 | * @return Container |
||
190 | */ |
||
191 | 1 | protected function createDependencies(array $serviceParams): Container |
|
204 | |||
205 | /** |
||
206 | * inject service in container |
||
207 | * |
||
208 | * @param mixed $serviceName |
||
209 | * @param array $serviceParams |
||
210 | * @return Container |
||
211 | */ |
||
212 | 1 | protected function injectService($serviceName, array $serviceParams): Container |
|
222 | |||
223 | /** |
||
224 | * return true is service class exists with a constructor |
||
225 | * |
||
226 | * @param mixed $serviceName |
||
227 | * @return boolean |
||
228 | */ |
||
229 | 1 | protected function constructable($value): bool |
|
243 | |||
244 | /** |
||
245 | * return true if service instanciated in container |
||
246 | * |
||
247 | * @param string $serviceName |
||
248 | * @return boolean |
||
249 | */ |
||
250 | 1 | protected function hasService(string $serviceName): bool |
|
260 | |||
261 | /** |
||
262 | * return true if is boolean or int types |
||
263 | * |
||
264 | * @param mixed $value |
||
265 | * @return boolean |
||
266 | */ |
||
267 | 1 | protected function isBasicType($value): bool |
|
271 | |||
272 | /** |
||
273 | * set config for service |
||
274 | * testing purpose |
||
275 | * |
||
276 | * @param array $servicesConfig |
||
277 | * @return Container |
||
278 | */ |
||
279 | 1 | protected function setServiceConfig(array $servicesConfig): Container |
|
284 | } |
||
285 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.