1 | <?php |
||
15 | class Container implements \ArrayAccess, ContainerInterface |
||
16 | { |
||
17 | protected $locked = []; |
||
18 | private $aliasOf = []; |
||
19 | private $factories; |
||
20 | private $hasAliases = []; |
||
21 | private $raw = []; |
||
22 | private $values = []; |
||
23 | |||
24 | public function __construct() |
||
28 | |||
29 | /** |
||
30 | * Checks if a parameter or an object is defined. |
||
31 | * |
||
32 | * @param string $id the parameter/object identifier to check |
||
33 | * @return boolean |
||
34 | */ |
||
35 | public function offsetExists($id): bool |
||
39 | |||
40 | /** |
||
41 | * Gets a parameter or an object. |
||
42 | * |
||
43 | * @param string $id the parameter/object identifier |
||
44 | * @return mixed The requested value |
||
45 | * @throws \InvalidArgumentException if provided identifier is not defined |
||
46 | */ |
||
47 | public function offsetGet($id) |
||
66 | |||
67 | /** |
||
68 | * Sets a parameter or an object. |
||
69 | * |
||
70 | * Note that you cannot override locked value, you have to call ::offsetUnset first. |
||
71 | * |
||
72 | * @param string $id the identifier for parameter or object |
||
73 | * @param mixed $v the value of the parameter or an object |
||
74 | * @throws \RuntimeException prevents override of locked value |
||
75 | * @throws \InvalidArgumentException prevents value's identifier to be equal to an existing alias |
||
76 | */ |
||
77 | public function offsetSet($id, $v): void |
||
89 | |||
90 | /** |
||
91 | * Unsets a parameter or an object. It can also unset an alias. |
||
92 | * |
||
93 | * Note that if you unset a value it will also unset all its aliases. |
||
94 | * |
||
95 | * @param string $id the identifier of the object/parameter to unset |
||
96 | */ |
||
97 | public function offsetUnset($id): void |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | * {@see ContainerInterface::get} |
||
119 | * |
||
120 | * This method has been added to be compatible with PSR-11. |
||
121 | */ |
||
122 | public function get($id) |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | * {@see ContainerInterface::has} |
||
137 | * |
||
138 | * This method has been added to be compatible with PSR-11. |
||
139 | */ |
||
140 | public function has($id) |
||
144 | |||
145 | /** |
||
146 | * Adds alias to service's identifier. |
||
147 | * |
||
148 | * @param string $alias the alias to identifier |
||
149 | * @param string $id the identifier to alias |
||
150 | * @return self |
||
151 | * @throws InvalidArgumentException if provided identifier is undefined or if alias is |
||
152 | * equals to identifier |
||
153 | */ |
||
154 | public function alias(string $alias, string $id): void |
||
168 | |||
169 | /** |
||
170 | * Retrieves parameter and/or object by identifier. |
||
171 | * this method also support wildcard character (*) in identifier. |
||
172 | * |
||
173 | * @param string $id this identifier can contain one or many wildcard character (*) |
||
174 | * @return array an array of values that mached with provided identifier pattern |
||
175 | */ |
||
176 | public function find(string $id): array |
||
188 | |||
189 | /** |
||
190 | * Returns all defined identifiers and aliases. |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function keys(): array |
||
198 | |||
199 | /** |
||
200 | * Add provided service as factory. |
||
201 | * |
||
202 | * @param string $id the factory identifier |
||
203 | * @param mixed $factory the factory object |
||
204 | * @return self |
||
205 | * @throws InvalidArgumentException if provided factory is not a Closure or not an invokable object |
||
206 | */ |
||
207 | public function factory(string $id, $factory): void |
||
216 | |||
217 | /** |
||
218 | * Locks an object or a parameter so you can not override it until unset() is called. |
||
219 | * |
||
220 | * @param string|array $ids the identifier(s) to lock |
||
221 | * @return self |
||
222 | */ |
||
223 | public function lock($ids): void |
||
229 | |||
230 | /** |
||
231 | * Returns associated identifier if provided argument is an alias. |
||
232 | * |
||
233 | * @param string $id the identifier to convert if needed |
||
234 | * @return string |
||
235 | * @throws \InvalidArgumentException if provided identifier is not defined |
||
236 | */ |
||
237 | private function resolveIdentifier(string $id): string |
||
245 | } |
||
246 |