1 | <?php |
||
18 | abstract class AbstractContainer implements ContainerInterface |
||
19 | { |
||
20 | /** Default logic function name */ |
||
21 | const LOGIC_FUNCTION_NAME = 'diContainer'; |
||
22 | |||
23 | /** @var array[string] Collection of alias => class name for alias resolving */ |
||
24 | protected $aliases = array(); |
||
25 | |||
26 | /** @var array[string] Collection of entity name resolving */ |
||
27 | protected $resolver = array(); |
||
28 | |||
29 | /** @var array[string] Collection of class name dependencies trees */ |
||
30 | protected $dependencies = array(); |
||
31 | |||
32 | /** @var ContainerInterface[] Collection of delegated containers */ |
||
33 | protected $delegates = array(); |
||
34 | |||
35 | /** @var array[string] Collection of dependency parameters */ |
||
36 | protected $parameters = array(); |
||
37 | |||
38 | /** @var \samsonphp\generator\Generator */ |
||
39 | protected $generator; |
||
40 | |||
41 | /** |
||
42 | * Container constructor. |
||
43 | * |
||
44 | * @param Generator $generator |
||
45 | */ |
||
46 | 2 | public function __construct(Generator $generator) |
|
50 | |||
51 | /** |
||
52 | * Help container resolving interfaces and abstract classes or any entities to |
||
53 | * different one. |
||
54 | * |
||
55 | * @param string $source Source entity name |
||
56 | * @param string $destination Destination entity name |
||
57 | * |
||
58 | * @return self Chaining |
||
59 | */ |
||
60 | public function resolve($source, $destination) |
||
66 | |||
67 | /** |
||
68 | * Internal logic handler. Calls generated logic function |
||
69 | * for performing entity creation or search. This is encapsulated |
||
70 | * method for further overriding. |
||
71 | * |
||
72 | * @param string $alias Entity alias |
||
73 | * |
||
74 | * @return mixed Created instance or null |
||
75 | */ |
||
76 | 1 | protected function logic($alias) |
|
80 | |||
81 | /** |
||
82 | * Finds an entry of the container by its identifier and returns it. |
||
83 | * |
||
84 | * @param string $alias Identifier of the entry to look for. |
||
85 | * |
||
86 | * @throws NotFoundException No entry was found for this identifier. |
||
87 | * @throws ContainerException Error while retrieving the entry. |
||
88 | * |
||
89 | * @return mixed Entry. |
||
90 | */ |
||
91 | 1 | public function get($alias) |
|
119 | |||
120 | /** |
||
121 | * Implementing delegate lookup feature. |
||
122 | * If current container cannot resolve entity dependency |
||
123 | * resolving process is passed to delegated container. |
||
124 | * |
||
125 | * @param ContainerInterface $container Container for delegate lookup |
||
126 | */ |
||
127 | 2 | public function delegate(ContainerInterface $container) |
|
131 | |||
132 | /** |
||
133 | * Returns true if the container can return an entry for the given identifier. |
||
134 | * Returns false otherwise. |
||
135 | * |
||
136 | * @param string $alias Identifier of the entry to look for. |
||
137 | * |
||
138 | * @return boolean |
||
139 | */ |
||
140 | 1 | public function has($alias) |
|
155 | |||
156 | /** |
||
157 | * Generate logic conditions and their implementation for container and its delegates. |
||
158 | * |
||
159 | * @param string $inputVariable Input condition parameter variable name |
||
160 | * @param bool|false $started Flag if condition branching has been started |
||
161 | */ |
||
162 | 2 | public function generateConditions($inputVariable = '$alias', $started = false) |
|
186 | |||
187 | /** |
||
188 | * Generate dependency injection logic function. |
||
189 | * |
||
190 | * @param string $functionName |
||
191 | * |
||
192 | * @return string PHP logic function code |
||
193 | */ |
||
194 | 2 | public function generateFunction($functionName = self::LOGIC_FUNCTION_NAME) |
|
211 | |||
212 | /** |
||
213 | * Set container dependency. |
||
214 | * |
||
215 | * @param mixed $entity Entity |
||
216 | * @param string|null $alias Entity alias for simplier finding |
||
217 | * @param array $parameters Collection of additional parameters |
||
218 | * |
||
219 | * @return self Chaining |
||
220 | */ |
||
221 | abstract public function set($entity, $alias = null, array $parameters = array()); |
||
222 | |||
223 | /** |
||
224 | * Generate container dependency condition code. |
||
225 | * @param string $alias Entity alias |
||
226 | * @param mixed $entity Entity |
||
227 | */ |
||
228 | abstract protected function generateCondition($alias, $entity); |
||
229 | } |
||
230 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: