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 | /** @var array Collection of scope => [alias => class_name] */ |
||
38 | protected $scopes = []; |
||
39 | |||
40 | /** |
||
41 | * Wrapper for calling dependency resolving function. |
||
42 | * |
||
43 | * @param string $dependency Dependency name |
||
44 | * |
||
45 | * @return mixed Created instance or null |
||
46 | * @throws ContainerException |
||
47 | */ |
||
48 | 5 | protected function logic($dependency) |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | * |
||
60 | * @throws \samsonframework\di\exception\ContainerException |
||
61 | * @throws \samsonframework\di\exception\ClassNotFoundException |
||
62 | */ |
||
63 | 5 | public function get($dependency) |
|
74 | |||
75 | /** |
||
76 | * Try to find dependency in delegate container. |
||
77 | * |
||
78 | * @param string $dependency Dependency identifier |
||
79 | * |
||
80 | * @return mixed Delegate found dependency |
||
81 | * |
||
82 | * @throws \Interop\Container\Exception\ContainerException |
||
83 | */ |
||
84 | 2 | protected function getFromDelegate(string $dependency) |
|
99 | |||
100 | /** |
||
101 | * Implementing delegate lookup feature. |
||
102 | * If current container cannot resolve entity dependency |
||
103 | * resolving process is passed to delegated container. |
||
104 | * |
||
105 | * @param ContainerInterface $container Container for delegate lookup |
||
106 | */ |
||
107 | 3 | public function delegate(ContainerInterface $container) |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 2 | public function has($dependency) : bool |
|
123 | |||
124 | /** |
||
125 | * Define if delegate containers have dependency. |
||
126 | * |
||
127 | * @param string $dependency Dependency identifier |
||
128 | * |
||
129 | * @return bool True if delegate containers have dependency |
||
130 | */ |
||
131 | 2 | protected function hasDelegate(string $dependency) : bool |
|
141 | |||
142 | /** |
||
143 | * Set service dependency. Upon first creation of this class instance |
||
144 | * it would be used everywhere where this dependency is needed. |
||
145 | * |
||
146 | * @param string $className Fully qualified class name |
||
147 | * @param array $parameters Collection of parameters needed for dependency creation |
||
148 | * @param string $alias Dependency name |
||
149 | * |
||
150 | * @return ContainerInterface Chaining |
||
151 | */ |
||
152 | 9 | public function service($className, array $parameters = [], string $alias = null) : ContainerInterface |
|
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | 9 | public function set($className, array $dependencies = [], string $alias = null) : ContainerInterface |
|
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | 1 | public function getServices(string $filterScope = null) : array |
|
195 | } |
||
196 |