1 | <?php declare(strict_types=1); |
||
17 | class Container implements ContainerInterface |
||
18 | { |
||
19 | /** @var array Collection of instantiated service instances */ |
||
20 | protected $serviceInstances = []; |
||
21 | |||
22 | /** @var array[string] Collection of loaded services */ |
||
23 | protected $services = []; |
||
24 | |||
25 | /** @var array[string] Collection of alias => class name for alias resolving */ |
||
26 | protected $aliases = []; |
||
27 | |||
28 | /** @var array[string] Collection of class name dependencies trees */ |
||
29 | protected $dependencies = []; |
||
30 | |||
31 | /** @var ContainerInterface[] Collection of delegated containers */ |
||
32 | protected $delegates = []; |
||
33 | |||
34 | /** @var callable Dependency resolving function callable */ |
||
35 | protected $logicCallable; |
||
36 | |||
37 | /** |
||
38 | * Wrapper for calling dependency resolving function. |
||
39 | * |
||
40 | * @param string $dependency Dependency name |
||
41 | * |
||
42 | * @return mixed Created instance or null |
||
43 | * @throws ContainerException |
||
44 | */ |
||
45 | 5 | protected function logic($dependency) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | * |
||
57 | * @throws \samsonframework\di\exception\ContainerException |
||
58 | * @throws \samsonframework\di\exception\ClassNotFoundException |
||
59 | */ |
||
60 | 5 | public function get($dependency) |
|
71 | |||
72 | /** |
||
73 | * Try to find dependency in delegate container. |
||
74 | * |
||
75 | * @param string $dependency Dependency identifier |
||
76 | * |
||
77 | * @return mixed Delegate found dependency |
||
78 | * |
||
79 | * @throws \Interop\Container\Exception\ContainerException |
||
80 | */ |
||
81 | 2 | protected function getFromDelegate(string $dependency) |
|
96 | |||
97 | /** |
||
98 | * Implementing delegate lookup feature. |
||
99 | * If current container cannot resolve entity dependency |
||
100 | * resolving process is passed to delegated container. |
||
101 | * |
||
102 | * @param ContainerInterface $container Container for delegate lookup |
||
103 | */ |
||
104 | 3 | public function delegate(ContainerInterface $container) |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 2 | public function has($dependency) : bool |
|
120 | |||
121 | /** |
||
122 | * Define if delegate containers have dependency. |
||
123 | * |
||
124 | * @param string $dependency Dependency identifier |
||
125 | * |
||
126 | * @return bool True if delegate containers have dependency |
||
127 | */ |
||
128 | 2 | protected function hasDelegate(string $dependency) : bool |
|
138 | |||
139 | /** |
||
140 | * Set service dependency. Upon first creation of this class instance |
||
141 | * it would be used everywhere where this dependency is needed. |
||
142 | * |
||
143 | * @param string $className Fully qualified class name |
||
144 | * @param array $parameters Collection of parameters needed for dependency creation |
||
145 | * @param string $alias Dependency name |
||
146 | * |
||
147 | * @return ContainerInterface Chaining |
||
148 | */ |
||
149 | 9 | public function service($className, array $parameters = [], string $alias = null) : ContainerInterface |
|
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | 9 | public function set($className, array $dependencies = [], string $alias = null) : ContainerInterface |
|
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | 1 | public function getServices(string $filterScope = null) : array |
|
192 | } |
||
193 |