1 | <?php |
||
23 | class Container implements ContainerInterface |
||
24 | { |
||
25 | /** @var array[string] Collection of loaded services */ |
||
26 | protected $services = array(); |
||
27 | |||
28 | /** @var array[string] Collection of alias => class name for alias resolving*/ |
||
29 | protected $aliases = array(); |
||
30 | |||
31 | /** @var array[string] Collection of class name dependencies trees */ |
||
32 | protected $dependencies = array(); |
||
33 | |||
34 | /** @var Generator */ |
||
35 | protected $generator; |
||
36 | |||
37 | 1 | public function __construct(Generator $generator) |
|
41 | |||
42 | /** |
||
43 | * Get reflection paramater class name type hint if present without |
||
44 | * autoloading and throwing exceptions. |
||
45 | * |
||
46 | * @param \ReflectionParameter $param Parameter for parsing |
||
47 | * |
||
48 | * @return string|null Class name typehint or null |
||
49 | */ |
||
50 | 1 | protected function getClassName(\ReflectionParameter $param) |
|
57 | |||
58 | /** |
||
59 | * Recursively build class constructor dependencies tree. |
||
60 | * TODO: Analyze recurrent dependencies and throw an exception |
||
61 | * |
||
62 | * @param string $className Current class name for analyzing |
||
63 | * @param array $dependencies Reference to tree for filling up |
||
64 | * |
||
65 | * @return array [string] Multidimensional array as dependency tree |
||
66 | * @throws ClassNotFoundException |
||
67 | */ |
||
68 | 1 | protected function buildDependenciesTree($className, array &$dependencies) |
|
107 | |||
108 | 1 | public function generateLogicConditions(array $dependencies, $class) |
|
145 | |||
146 | 1 | public function generateLogicFunction($functionName = 'diContainer') |
|
179 | |||
180 | /** |
||
181 | * Finds an entry of the container by its identifier and returns it. |
||
182 | * |
||
183 | * @param string $alias Identifier of the entry to look for. |
||
184 | * |
||
185 | * @throws NotFoundException No entry was found for this identifier. |
||
186 | * @throws ContainerException Error while retrieving the entry. |
||
187 | * |
||
188 | * @return mixed Entry. |
||
189 | */ |
||
190 | public function get($alias) |
||
205 | |||
206 | /** |
||
207 | * Returns true if the container can return an entry for the given identifier. |
||
208 | * Returns false otherwise. |
||
209 | * |
||
210 | * @param string $alias Identifier of the entry to look for. |
||
211 | * |
||
212 | * @return boolean |
||
213 | */ |
||
214 | public function has($alias) |
||
219 | |||
220 | /** |
||
221 | * Set dependency alias with callback function. |
||
222 | * |
||
223 | * @param callable $callable Callable to return dependency |
||
224 | * @param string $alias Dependency name |
||
225 | * |
||
226 | * @return self Chaining |
||
227 | */ |
||
228 | public function callback($callable, $alias = null) |
||
232 | |||
233 | /** |
||
234 | * Set service dependency. Upon first creation of this class instance |
||
235 | * it would be used everywhere where this dependency is needed. |
||
236 | * |
||
237 | * @param string $className Fully qualified class name |
||
238 | * @param string $alias Dependency name |
||
239 | * @param array $parameters Collection of parameters needed for dependency creation |
||
240 | * |
||
241 | * @return self Chaining |
||
242 | */ |
||
243 | public function service($className, $alias = null, array $parameters = array()) |
||
247 | |||
248 | /** |
||
249 | * Set service dependency by passing object instance. |
||
250 | * |
||
251 | * @param mixed $instance Instance that needs to be return by this dependency |
||
252 | * @param string $alias Dependency name |
||
253 | * @param array $parameters Collection of parameters needed for dependency creation |
||
254 | * |
||
255 | * @return self Chaining |
||
256 | */ |
||
257 | public function instance(&$instance, $alias = null, array $parameters = array()) |
||
262 | |||
263 | /** |
||
264 | * Set dependency. |
||
265 | * |
||
266 | * @param string $className Fully qualified class name |
||
267 | * @param string $alias Dependency name |
||
268 | * @param array $parameters Collection of parameters needed for dependency creation |
||
269 | * |
||
270 | * @return ContainerInterface Chaining |
||
271 | */ |
||
272 | 1 | public function set($className, $alias = null, array $parameters = array()) |
|
286 | } |
||
287 |