1 | <?php |
||
18 | class Container implements \ArrayAccess, ContainerInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $aliases = []; |
||
24 | |||
25 | /** |
||
26 | * Array of Definitions. |
||
27 | * |
||
28 | * @var Definition[] |
||
29 | */ |
||
30 | protected $definitions = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $instances; |
||
36 | |||
37 | /** |
||
38 | * Array of parameters. |
||
39 | * |
||
40 | * @var ParameterBag |
||
41 | */ |
||
42 | protected $parameters; |
||
43 | |||
44 | /** |
||
45 | * @var Resolver |
||
46 | */ |
||
47 | protected $resolver; |
||
48 | |||
49 | /** |
||
50 | * Defaults for the container. |
||
51 | * |
||
52 | * [ |
||
53 | * 'share' => true, |
||
54 | * 'autowire' => true |
||
55 | * ] |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $defaults = [ |
||
60 | 'share' => true, |
||
61 | 'autowire' => true, |
||
62 | ]; |
||
63 | |||
64 | public function __construct() |
||
70 | |||
71 | /** |
||
72 | * Determine if a given offset exists. |
||
73 | * |
||
74 | * @param string $key |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function offsetExists($key) |
||
82 | |||
83 | /** |
||
84 | * Get the value at a given offset. |
||
85 | * |
||
86 | * @param string $key |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function offsetGet($key) |
||
94 | |||
95 | /** |
||
96 | * Set the value at a given offset. |
||
97 | * |
||
98 | * @param string $key |
||
99 | * @param mixed $value |
||
100 | */ |
||
101 | public function offsetSet($key, $value) |
||
105 | |||
106 | /** |
||
107 | * Unset the value at a given offset. |
||
108 | * |
||
109 | * @param string $key |
||
110 | */ |
||
111 | public function offsetUnset($key) |
||
115 | |||
116 | /** |
||
117 | * Register a definition. |
||
118 | * |
||
119 | * @param string|object $id |
||
120 | * @param mixed $concrete |
||
121 | * |
||
122 | * @return Definition |
||
123 | */ |
||
124 | public function register($id, $concrete = null) |
||
141 | |||
142 | /** |
||
143 | * Set a definition. |
||
144 | * |
||
145 | * @param string $id |
||
146 | * @param Definition $definition |
||
147 | * |
||
148 | * @return Definition |
||
149 | */ |
||
150 | public function setDefinition($id, Definition $definition) |
||
156 | |||
157 | /** |
||
158 | * Sets an alias for an existing service. |
||
159 | * |
||
160 | * @param string $alias |
||
161 | * @param string $id |
||
162 | */ |
||
163 | public function setAlias($alias, $id) |
||
167 | |||
168 | /** |
||
169 | * Get id of the alias. |
||
170 | * |
||
171 | * @param string $alias |
||
172 | * |
||
173 | * @return string|null |
||
174 | */ |
||
175 | public function getAlias($alias) |
||
179 | |||
180 | /** |
||
181 | * Get a service instance by specified ID. |
||
182 | * |
||
183 | * @param string $id |
||
184 | * |
||
185 | * @return object |
||
186 | */ |
||
187 | public function get($id) |
||
211 | |||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | public function has($id) |
||
219 | |||
220 | /** |
||
221 | * Extends a definition. |
||
222 | * |
||
223 | * @param string $id |
||
224 | * |
||
225 | * @return Definition |
||
226 | */ |
||
227 | public function extend($id) |
||
239 | |||
240 | /** |
||
241 | * Returns service ids for a given tag. |
||
242 | * |
||
243 | * Example: |
||
244 | * |
||
245 | * $container->register('foo')->addTag('my.tag', array('hello' => 'world')); |
||
246 | * |
||
247 | * $serviceIds = $container->findTaggedServiceIds('my.tag'); |
||
248 | * foreach ($serviceIds as $serviceId => $tags) { |
||
249 | * foreach ($tags as $tag) { |
||
250 | * echo $tag['hello']; |
||
251 | * } |
||
252 | * } |
||
253 | * |
||
254 | * @param string $name |
||
255 | * |
||
256 | * @return array |
||
257 | */ |
||
258 | public function findTaggedServiceIds($name) |
||
269 | |||
270 | /** |
||
271 | * Gets all global parameters. |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | public function getParameters() |
||
279 | |||
280 | /** |
||
281 | * Sets array of parameters. |
||
282 | * |
||
283 | * @param array $parameterStore |
||
284 | */ |
||
285 | public function setParameters(array $parameterStore) |
||
289 | |||
290 | /** |
||
291 | * Add some parameters. |
||
292 | * |
||
293 | * @param array $parameters |
||
294 | */ |
||
295 | public function addParameters(array $parameters) |
||
299 | |||
300 | /** |
||
301 | * Sets a parameter with its name and value. |
||
302 | * |
||
303 | * @param $name |
||
304 | * @param mixed $value |
||
305 | */ |
||
306 | public function setParameter($name, $value) |
||
310 | |||
311 | /** |
||
312 | * Gets a parameter by given name. |
||
313 | * |
||
314 | * @param $name |
||
315 | * @param mixed $default |
||
316 | * |
||
317 | * @return mixed |
||
318 | */ |
||
319 | public function getParameter($name, $default = null) |
||
323 | |||
324 | /** |
||
325 | * Gets a default option of the container. |
||
326 | * |
||
327 | * @param string $option |
||
328 | * |
||
329 | * @return mixed|null|boolean |
||
330 | */ |
||
331 | public function getDefault($option) |
||
335 | |||
336 | /** |
||
337 | * Configure defaults. |
||
338 | * |
||
339 | * @param array $defaults |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | public function setDefaults(array $defaults) |
||
347 | } |
||
348 |