1 | <?php declare(strict_types=1); |
||
16 | class Container implements ContainerInterface |
||
17 | { |
||
18 | /** @var array Collection of instantiated service instances */ |
||
19 | protected $serviceInstances = []; |
||
20 | /** @var array[string] Collection of loaded services */ |
||
21 | protected $services = []; |
||
22 | /** @var array[string] Collection of alias => class name for alias resolving */ |
||
23 | protected $aliases = []; |
||
24 | /** @var array[string] Collection of class name dependencies trees */ |
||
25 | protected $dependencies = []; |
||
26 | /** @var ContainerInterface[] Collection of delegated containers */ |
||
27 | protected $delegates = []; |
||
28 | /** @var callable Dependency resolving function callable */ |
||
29 | protected $logicCallable; |
||
30 | /** @var array Collection of scope => [alias => class_name] */ |
||
31 | protected $scopes = []; |
||
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 | 5 | protected function logic($dependency) |
|
41 | { |
||
42 | 5 | if (!is_callable($this->logicCallable)) { |
|
43 | 2 | throw new ContainerException('Logic function is not callable'); |
|
44 | } |
||
45 | 4 | return call_user_func($this->logicCallable, $dependency); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get parameter |
||
50 | * |
||
51 | * @param $name |
||
52 | */ |
||
53 | public function getParameter($name) |
||
54 | { |
||
55 | return $this->parameter($name); |
||
|
|||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | * |
||
61 | * @throws \samsonframework\di\exception\ContainerException |
||
62 | * @throws \samsonframework\di\exception\ClassNotFoundException |
||
63 | */ |
||
64 | 5 | public function get($dependency) |
|
65 | { |
||
66 | // Get pointer from logic |
||
67 | 5 | $module = $this->logic($dependency) ?? $this->getFromDelegate($dependency); |
|
68 | 4 | if (null === $module) { |
|
69 | 1 | throw new ClassNotFoundException($dependency); |
|
70 | } else { |
||
71 | 3 | return $module; |
|
72 | } |
||
73 | } |
||
74 | /** |
||
75 | * Try to find dependency in delegate container. |
||
76 | * |
||
77 | * @param string $dependency Dependency identifier |
||
78 | * |
||
79 | * @return mixed Delegate found dependency |
||
80 | * |
||
81 | * @throws \Interop\Container\Exception\ContainerException |
||
82 | */ |
||
83 | 2 | protected function getFromDelegate(string $dependency) |
|
84 | { |
||
85 | // Try delegate lookup |
||
86 | 2 | foreach ($this->delegates as $delegate) { |
|
87 | try { |
||
88 | 2 | return $delegate->get($dependency); |
|
89 | 1 | } catch (ContainerException $e) { |
|
90 | // Catch all delegated exceptions |
||
91 | 1 | } catch (ClassNotFoundException $e) { |
|
92 | // Catch all delegated exceptions |
||
93 | } |
||
94 | } |
||
95 | 1 | return null; |
|
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 | * {@inheritdoc} |
||
110 | */ |
||
111 | 2 | public function has($dependency) : bool |
|
112 | { |
||
118 | /** |
||
119 | * Define if delegate containers have dependency. |
||
120 | * |
||
121 | * @param string $dependency Dependency identifier |
||
122 | * |
||
123 | * @return bool True if delegate containers have dependency |
||
124 | */ |
||
125 | 2 | protected function hasDelegate(string $dependency) : bool |
|
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 | 9 | public function service($className, array $parameters = [], string $alias = null) : ContainerInterface |
|
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | 9 | public function set($className, array $dependencies = [], string $alias = null) : ContainerInterface |
|
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | 1 | public function getServices(string $filterScope = null) : array |
|
178 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.