1 | <?php |
||
11 | class Container extends AbstractContainer |
||
12 | { |
||
13 | /** Variable name for storing services */ |
||
14 | const STATIC_COLLECTION_VARIABLE = '$services'; |
||
15 | |||
16 | /** @var array[string] Collection of loaded services */ |
||
17 | protected $services = array(); |
||
18 | |||
19 | /** |
||
20 | * Get reflection parameter class name type hint if present without |
||
21 | * auto loading and throwing exceptions. |
||
22 | * TODO: Add resolving configured classes |
||
23 | * |
||
24 | * @param \ReflectionParameter $param Parameter for parsing |
||
25 | * |
||
26 | * @return string|null Class name typehint or null |
||
27 | */ |
||
28 | protected function getClassName(\ReflectionParameter $param) |
||
35 | |||
36 | /** |
||
37 | * Analyze class construtor dependencies and create tree for nested dependencies. |
||
38 | * |
||
39 | * @param \ReflectionMethod $constructor Reflection method __constructor instance |
||
40 | * @param string $className |
||
41 | * @param array $dependencies Reference to tree for filling up |
||
42 | * |
||
43 | * @throws ClassNotFoundException |
||
44 | */ |
||
45 | protected function buildConstructorDependencies(\ReflectionMethod $constructor, $className, &$dependencies) |
||
69 | |||
70 | /** |
||
71 | * Recursively build class constructor dependencies tree. |
||
72 | * TODO: Analyze recurrent dependencies and throw an exception |
||
73 | * |
||
74 | * @param string $className Current class name for analyzing |
||
75 | * @param array $dependencies Reference to tree for filling up |
||
76 | * |
||
77 | * @return array [string] Multidimensional array as dependency tree |
||
78 | * @throws ClassNotFoundException |
||
79 | */ |
||
80 | protected function buildDependenciesTree($className, array &$dependencies) |
||
101 | |||
102 | /** |
||
103 | * Set service dependency. Upon first creation of this class instance |
||
104 | * it would be used everywhere where this dependency is needed. |
||
105 | * |
||
106 | * @param string $className Fully qualified class name |
||
107 | * @param string $alias Dependency name |
||
108 | * @param array $parameters Collection of parameters needed for dependency creation |
||
109 | * |
||
110 | * @return Container Chaining |
||
111 | */ |
||
112 | public function service($className, $alias = null, array $parameters = array()) |
||
118 | |||
119 | /** |
||
120 | * Set dependency. |
||
121 | * |
||
122 | * @param string $className Fully qualified class name |
||
123 | * @param string $alias Dependency name |
||
124 | * @param array $parameters Collection of parameters needed for dependency creation |
||
125 | * |
||
126 | * @return Container Chaining |
||
127 | */ |
||
128 | public function set($className, $alias = null, array $parameters = array()) |
||
142 | |||
143 | /** |
||
144 | * Generate initial class instance declaration |
||
145 | * @param string $className Entity class name |
||
146 | */ |
||
147 | protected function generateInitialDeclaration($className) |
||
160 | |||
161 | /** |
||
162 | * Parse class dependencies generated by dependency tree. |
||
163 | * |
||
164 | * @param mixed $dependency Dependency value |
||
165 | * @param string $variable Dependency name |
||
166 | * @param string $className |
||
167 | * @param int $level Current recursion level |
||
168 | * |
||
169 | * @throws ConstructorParameterNotSetException |
||
170 | */ |
||
171 | protected function parseClassDependencies($dependency, $variable, $className, $level) |
||
192 | |||
193 | /** |
||
194 | * Generate container dependency condition code. |
||
195 | * |
||
196 | * @param string $className |
||
197 | * @param mixed $dependencies |
||
198 | * @param int $level |
||
199 | * |
||
200 | * @throws ConstructorParameterNotSetException |
||
201 | * |
||
202 | */ |
||
203 | protected function generateCondition($className, &$dependencies, $level = 0) |
||
225 | } |
||
226 |