1 | <?php |
||
21 | class Container implements ContainerInterface |
||
22 | { |
||
23 | /** @var array[string] Collection of loaded services */ |
||
24 | protected $services = array(); |
||
25 | |||
26 | /** @var array[string] Collection of alias => class name for alias resolving*/ |
||
27 | protected $aliases = array(); |
||
28 | |||
29 | /** @var array[string] Collection of class name dependencies trees */ |
||
30 | protected $dependencies = array(); |
||
31 | |||
32 | /** |
||
33 | * Get reflection paramater class name type hint if present without |
||
34 | * autoloading and throwing exceptions. |
||
35 | * |
||
36 | * @param \ReflectionParameter $param Parameter for parsing |
||
37 | * |
||
38 | * @return string|null Class name typehint or null |
||
39 | */ |
||
40 | 1 | protected function getClassName(\ReflectionParameter $param) { |
|
44 | |||
45 | /** |
||
46 | * Recursively build class constructor dependencies tree. |
||
47 | * TODO: Analyze recurrent dependencies and throw an error |
||
48 | * |
||
49 | * @param string $className Current class name for analyzing |
||
50 | * @param array $dependencies Reference to tree for filling up |
||
51 | * |
||
52 | * @return array [string] Multidimensional array as dependency tree |
||
53 | * @throws ClassNotFoundException |
||
54 | */ |
||
55 | 1 | protected function buildDependenciesTree($className, array &$dependencies = array()) |
|
89 | |||
90 | /** |
||
91 | * Finds an entry of the container by its identifier and returns it. |
||
92 | * |
||
93 | * @param string $id Identifier of the entry to look for. |
||
94 | * |
||
95 | * @throws NotFoundException No entry was found for this identifier. |
||
96 | * @throws ContainerException Error while retrieving the entry. |
||
97 | * |
||
98 | * @return mixed Entry. |
||
99 | */ |
||
100 | public function get($id) |
||
115 | |||
116 | /** |
||
117 | * Returns true if the container can return an entry for the given identifier. |
||
118 | * Returns false otherwise. |
||
119 | * |
||
120 | * @param string $id Identifier of the entry to look for. |
||
121 | * |
||
122 | * @return boolean |
||
123 | */ |
||
124 | public function has($id) |
||
128 | |||
129 | /** |
||
130 | * Set dependency alias with callback function. |
||
131 | * |
||
132 | * @param callable $callable Callable to return dependency |
||
133 | * @param string $alias Dependency name |
||
134 | * |
||
135 | * @return self Chaining |
||
136 | */ |
||
137 | public function callback($callable, $alias = null) |
||
141 | |||
142 | /** |
||
143 | * Set service dependency. Upon first creation of this class instance |
||
144 | * it would be used everywhere where this dependency is needed. |
||
145 | * |
||
146 | * @param string $className Fully qualified class name |
||
147 | * @param string $alias Dependency name |
||
148 | * @param array $parameters Collection of parameters needed for dependency creation |
||
149 | * |
||
150 | * @return self Chaining |
||
151 | */ |
||
152 | public function service($className, $alias = null, array $parameters = array()) |
||
156 | |||
157 | /** |
||
158 | * Set service dependency by passing object instance. |
||
159 | * |
||
160 | * @param mixed $instance Instance that needs to be return by this dependency |
||
161 | * @param string $alias Dependency name |
||
162 | * @param array $parameters Collection of parameters needed for dependency creation |
||
163 | * |
||
164 | * @return self Chaining |
||
165 | */ |
||
166 | public function instance(&$instance, $alias = null, array $parameters = array()) |
||
171 | |||
172 | /** |
||
173 | * Set dependency. |
||
174 | * |
||
175 | * @param string $className Fully qualified class name |
||
176 | * @param string $alias Dependency name |
||
177 | * @param array $parameters Collection of parameters needed for dependency creation |
||
178 | * |
||
179 | * @return ContainerInterface Chaining |
||
180 | */ |
||
181 | 1 | public function set($className, $alias = null, array $parameters = array()) |
|
194 | } |
||
195 |