1 | <?php |
||
24 | class Container implements ContainerInterface |
||
25 | { |
||
26 | const LOGIC_FUNCTION_NAME = 'diContainer'; |
||
27 | |||
28 | /** @var array[string] Collection of alias => class name for alias resolving */ |
||
29 | protected $aliases = array(); |
||
30 | |||
31 | /** @var array[string] Collection of alias => closure for alias resolving */ |
||
32 | protected $callbacks = array(); |
||
33 | |||
34 | /** @var array[string] Collection of loaded services */ |
||
35 | protected $services = array(); |
||
36 | |||
37 | /** @var array[string] Collection of class name dependencies trees */ |
||
38 | protected $dependencies = array(); |
||
39 | |||
40 | /** @var Generator */ |
||
41 | protected $generator; |
||
42 | |||
43 | /** |
||
44 | * Container constructor. |
||
45 | * |
||
46 | * @param Generator $generator |
||
47 | */ |
||
48 | 4 | public function __construct(Generator $generator) |
|
52 | |||
53 | /** |
||
54 | * Internal logic handler. Calls generated logic function |
||
55 | * for performing entity creation or search. This is encapsulated |
||
56 | * method for further overriding. |
||
57 | * |
||
58 | * @param string $alias Entity alias |
||
59 | * |
||
60 | * @return mixed Created instance or null |
||
61 | */ |
||
62 | 3 | protected function logic($alias) |
|
66 | |||
67 | /** |
||
68 | * Get reflection paramater class name type hint if present without |
||
69 | * auto loading and throwing exceptions. |
||
70 | * |
||
71 | * @param \ReflectionParameter $param Parameter for parsing |
||
72 | * |
||
73 | * @return string|null Class name typehint or null |
||
74 | */ |
||
75 | 4 | protected function getClassName(\ReflectionParameter $param) |
|
82 | |||
83 | /** |
||
84 | * Recursively build class constructor dependencies tree. |
||
85 | * TODO: Analyze recurrent dependencies and throw an exception |
||
86 | * |
||
87 | * @param string $className Current class name for analyzing |
||
88 | * @param array $dependencies Reference to tree for filling up |
||
89 | * |
||
90 | * @return array [string] Multidimensional array as dependency tree |
||
91 | * @throws ClassNotFoundException |
||
92 | */ |
||
93 | 4 | protected function buildDependenciesTree($className, array &$dependencies) |
|
129 | |||
130 | /** |
||
131 | * Recursive object creation with dependencies. |
||
132 | * |
||
133 | * @param array $dependencies Collection of current class dependenices |
||
134 | * @param string $class Current class name |
||
135 | * |
||
136 | * @throws ConstructorParameterNotSetException |
||
137 | */ |
||
138 | |||
139 | 1 | public function generateLogicConditions(array &$dependencies, $class) |
|
184 | |||
185 | /** |
||
186 | * Generate callback logic implementation as plain code. |
||
187 | * |
||
188 | * @param string $className Callback alias |
||
189 | */ |
||
190 | 1 | protected function generateCallback($className) |
|
218 | |||
219 | /** |
||
220 | * @param string $functionName |
||
221 | * |
||
222 | * @return string |
||
223 | * @throws ConstructorParameterNotSetException |
||
224 | */ |
||
225 | 1 | public function generateLogicFunction($functionName = self::LOGIC_FUNCTION_NAME) |
|
261 | |||
262 | /** |
||
263 | * Finds an entry of the container by its identifier and returns it. |
||
264 | * |
||
265 | * @param string $alias Identifier of the entry to look for. |
||
266 | * |
||
267 | * @throws NotFoundException No entry was found for this identifier. |
||
268 | * @throws ContainerException Error while retrieving the entry. |
||
269 | * |
||
270 | * @return mixed Entry. |
||
271 | */ |
||
272 | 3 | public function get($alias) |
|
287 | |||
288 | /** |
||
289 | * Returns true if the container can return an entry for the given identifier. |
||
290 | * Returns false otherwise. |
||
291 | * |
||
292 | * @param string $alias Identifier of the entry to look for. |
||
293 | * |
||
294 | * @return boolean |
||
295 | */ |
||
296 | 1 | public function has($alias) |
|
302 | |||
303 | /** |
||
304 | * Set dependency alias with callback function. |
||
305 | * |
||
306 | * @param callable $callable Callable to return dependency |
||
307 | * @param string $alias Dependency name |
||
308 | * |
||
309 | * @return self Chaining |
||
310 | */ |
||
311 | 4 | public function callback($callable, $alias = null) |
|
322 | |||
323 | /** |
||
324 | * Set service dependency. Upon first creation of this class instance |
||
325 | * it would be used everywhere where this dependency is needed. |
||
326 | * |
||
327 | * @param string $className Fully qualified class name |
||
328 | * @param string $alias Dependency name |
||
329 | * @param array $parameters Collection of parameters needed for dependency creation |
||
330 | * |
||
331 | * @return self Chaining |
||
332 | */ |
||
333 | 4 | public function service($className, $alias = null, array $parameters = array()) |
|
339 | |||
340 | /** |
||
341 | * Set service dependency by passing object instance. |
||
342 | * |
||
343 | * @param mixed $instance Instance that needs to be return by this dependency |
||
344 | * @param string $alias Dependency name |
||
345 | * @param array $parameters Collection of parameters needed for dependency creation |
||
346 | * |
||
347 | * @return self Chaining |
||
348 | */ |
||
349 | public function instance(&$instance, $alias = null, array $parameters = array()) |
||
354 | |||
355 | /** |
||
356 | * Set dependency. |
||
357 | * |
||
358 | * @param string $className Fully qualified class name |
||
359 | * @param string $alias Dependency name |
||
360 | * @param array $parameters Collection of parameters needed for dependency creation |
||
361 | * |
||
362 | * @return self Chaining |
||
363 | */ |
||
364 | 4 | public function set($className, $alias = null, array $parameters = array()) |
|
378 | } |
||
379 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.