1 | <?php |
||
47 | class Container implements ContainerInterface |
||
48 | { |
||
49 | /** |
||
50 | * Instantiate the container. |
||
51 | * |
||
52 | * Objects and parameters can be passed as argument to the constructor. |
||
53 | * |
||
54 | * @param array $values The parameters or objects. |
||
55 | * |
||
56 | * @throws \RuntimeException |
||
57 | */ |
||
58 | 28 | public function __construct(array $values = []) |
|
66 | /** |
||
67 | * Extends an object definition. |
||
68 | * |
||
69 | * Useful when you want to extend an existing object definition, |
||
70 | * without necessarily loading that object. |
||
71 | * |
||
72 | * @param string $id The unique identifier for the object |
||
73 | * @param callable $callable A service definition to extend the original |
||
74 | * |
||
75 | * @return callable The wrapped callable |
||
76 | * |
||
77 | * @throws \InvalidArgumentException if the identifier is not defined or not a service definition |
||
78 | */ |
||
79 | 5 | public function extend(string $id, callable $callable): callable |
|
97 | /** |
||
98 | * Marks a callable as being a factory service. |
||
99 | * |
||
100 | * @param callable $callable A service definition to be used as a factory |
||
101 | * |
||
102 | * @return callable The passed callable |
||
103 | * |
||
104 | * @throws \InvalidArgumentException Service definition has to be a closure of an invokable object |
||
105 | */ |
||
106 | 2 | public function factory(callable $callable): callable |
|
112 | /** |
||
113 | * Returns all defined value names. |
||
114 | * |
||
115 | * @return array An array of value names |
||
116 | */ |
||
117 | 4 | public function keys(): array |
|
121 | /** |
||
122 | * Checks if a parameter or an object is set. |
||
123 | * |
||
124 | * @param string $id The unique identifier for the parameter or object |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | 25 | public function offsetExists($id) |
|
132 | /** |
||
133 | * Gets a parameter or an object. |
||
134 | * |
||
135 | * @param string $id The unique identifier for the parameter or object |
||
136 | * |
||
137 | * @return mixed The value of the parameter or an object |
||
138 | * |
||
139 | * @throws \InvalidArgumentException if the identifier is not defined |
||
140 | */ |
||
141 | 19 | public function offsetGet($id) |
|
162 | /** |
||
163 | * Sets a parameter or an object. |
||
164 | * |
||
165 | * Objects must be defined as Closures. |
||
166 | * |
||
167 | * Allowing any PHP callable leads to difficult to debug problems |
||
168 | * as function names (strings) are callable (creating a function with |
||
169 | * the same name as an existing parameter would break your container). |
||
170 | * |
||
171 | * @param string $id The unique identifier for the parameter or object |
||
172 | * @param mixed $value The value of the parameter or a closure to define an object |
||
173 | * |
||
174 | * @throws \RuntimeException Prevent override of a frozen service |
||
175 | */ |
||
176 | 23 | public function offsetSet($id, $value) |
|
184 | /** |
||
185 | * Unsets a parameter or an object. |
||
186 | * |
||
187 | * @param string $id The unique identifier for the parameter or object |
||
188 | */ |
||
189 | 3 | public function offsetUnset($id) |
|
198 | /** |
||
199 | * Protects a callable from being interpreted as a service. |
||
200 | * |
||
201 | * This is useful when you want to store a callable as a parameter. |
||
202 | * |
||
203 | * @param callable $callable A callable to protect from being evaluated |
||
204 | * |
||
205 | * @return callable The passed callable |
||
206 | * |
||
207 | * @throws \InvalidArgumentException Service definition has to be a closure of an invokable object |
||
208 | */ |
||
209 | 1 | public function protect(callable $callable): callable |
|
215 | /** |
||
216 | * Gets a parameter or the closure defining an object. |
||
217 | * |
||
218 | * @param string $id The unique identifier for the parameter or object |
||
219 | * |
||
220 | * @return mixed The value of the parameter or the closure defining an object |
||
221 | * |
||
222 | * @throws \InvalidArgumentException if the identifier is not defined |
||
223 | */ |
||
224 | 3 | public function raw(string $id) |
|
234 | /** |
||
235 | * Registers a service provider. |
||
236 | * |
||
237 | * @param ServiceProviderInterface $provider A ServiceProviderInterface instance |
||
238 | * @param array $values An array of values that customizes the provider |
||
239 | * |
||
240 | * @return ContainerInterface |
||
241 | */ |
||
242 | 1 | public function register(ServiceProviderInterface $provider, array $values = []): ContainerInterface |
|
250 | /** |
||
251 | * @var \SplObjectStorage $factories |
||
252 | */ |
||
253 | private $factories; |
||
254 | /** |
||
255 | * @var bool[] $frozen |
||
256 | */ |
||
257 | private $frozen = []; |
||
258 | /** |
||
259 | * @var bool[] $keys |
||
260 | */ |
||
261 | private $keys = []; |
||
262 | /** |
||
263 | * @var \SplObjectStorage $protected |
||
264 | */ |
||
265 | private $protected; |
||
266 | /** |
||
267 | * @var mixed[] $raw |
||
268 | */ |
||
269 | private $raw = []; |
||
270 | /** |
||
271 | * @var mixed[] $values |
||
272 | */ |
||
273 | private $values = []; |
||
274 | } |
||
275 |