1 | <?php declare(strict_types=1); |
||
15 | class Container implements ContainerInterface |
||
16 | { |
||
17 | /** @var array[string] Collection of loaded services */ |
||
18 | protected $services = []; |
||
19 | |||
20 | /** @var array[string] Collection of alias => class name for alias resolving */ |
||
21 | protected $aliases = []; |
||
22 | |||
23 | /** @var array[string] Collection of class name dependencies trees */ |
||
24 | protected $dependencies = []; |
||
25 | |||
26 | /** @var ContainerInterface[] Collection of delegated containers */ |
||
27 | protected $delegates = []; |
||
28 | |||
29 | /** @var callable Dependency resolving function callable */ |
||
30 | protected $logicCallable; |
||
31 | |||
32 | /** |
||
33 | * Wrapper for calling dependency resolving function. |
||
34 | * |
||
35 | * @param string $dependency Dependency name |
||
36 | * |
||
37 | * @return mixed Created instance or null |
||
38 | * @throws ContainerException |
||
39 | */ |
||
40 | 4 | protected function logic($dependency) |
|
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | * |
||
52 | * @throws \samsonframework\di\exception\ContainerException |
||
53 | * @throws \samsonframework\di\exception\ClassNotFoundException |
||
54 | */ |
||
55 | 4 | public function get($dependency) |
|
66 | |||
67 | /** |
||
68 | * Try to find dependency in delegate container. |
||
69 | * |
||
70 | * @param string $dependency Dependency identifier |
||
71 | * |
||
72 | * @return mixed Delegate found dependency |
||
73 | * |
||
74 | * @throws \Interop\Container\Exception\ContainerException |
||
75 | */ |
||
76 | 2 | protected function getFromDelegate(string $dependency) |
|
91 | |||
92 | /** |
||
93 | * Implementing delegate lookup feature. |
||
94 | * If current container cannot resolve entity dependency |
||
95 | * resolving process is passed to delegated container. |
||
96 | * |
||
97 | * @param ContainerInterface $container Container for delegate lookup |
||
98 | */ |
||
99 | 3 | public function delegate(ContainerInterface $container) |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | 2 | public function has($dependency) : bool |
|
115 | |||
116 | /** |
||
117 | * Define if delegate containers have dependency. |
||
118 | * |
||
119 | * @param string $dependency Dependency identifier |
||
120 | * |
||
121 | * @return bool True if delegate containers have dependency |
||
122 | */ |
||
123 | 2 | protected function hasDelegate(string $dependency) : bool |
|
133 | |||
134 | /** |
||
135 | * Set service dependency. Upon first creation of this class instance |
||
136 | * it would be used everywhere where this dependency is needed. |
||
137 | * |
||
138 | * @param string $className Fully qualified class name |
||
139 | * @param array $parameters Collection of parameters needed for dependency creation |
||
140 | * @param string $alias Dependency name |
||
141 | * |
||
142 | * @return ContainerInterface Chaining |
||
143 | */ |
||
144 | 8 | public function service($className, array $parameters = [], string $alias = null) : ContainerInterface |
|
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | 8 | public function set($className, array $dependencies = [], string $alias = null) : ContainerInterface |
|
169 | } |
||
170 |