| 1 | <?php |
||
| 35 | class Container implements \ArrayAccess |
||
| 36 | { |
||
| 37 | |||
| 38 | private $values = array(); |
||
|
1 ignored issue
–
show
|
|||
| 39 | |||
| 40 | private $factories; |
||
|
1 ignored issue
–
show
|
|||
| 41 | |||
| 42 | private $protected; |
||
|
1 ignored issue
–
show
|
|||
| 43 | |||
| 44 | private $frozen = array(); |
||
|
1 ignored issue
–
show
|
|||
| 45 | |||
| 46 | private $raw = array(); |
||
|
1 ignored issue
–
show
|
|||
| 47 | |||
| 48 | private $keys = array(); |
||
|
1 ignored issue
–
show
|
|||
| 49 | |||
| 50 | /** |
||
| 51 | * Instantiate the container. |
||
| 52 | * |
||
| 53 | * Objects and parameters can be passed as argument to the constructor. |
||
| 54 | * |
||
| 55 | * @param array $values The parameters or objects. |
||
| 56 | */ |
||
| 57 | 65 | public function __construct(array $values = array()) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Sets a parameter or an object. |
||
| 69 | * |
||
| 70 | * Objects must be defined as Closures. |
||
| 71 | * |
||
| 72 | * Allowing any PHP callable leads to difficult to debug problems |
||
| 73 | * as function names (strings) are callable (creating a function with |
||
| 74 | * the same name as an existing parameter would break your container). |
||
| 75 | * |
||
| 76 | * @param string $id The unique identifier for the parameter or object. |
||
| 77 | * @param mixed $value The value of the parameter or a closure to define an object. |
||
| 78 | * |
||
| 79 | * @return void |
||
| 80 | * @throws \RuntimeException Prevent override of a frozen service. |
||
| 81 | */ |
||
| 82 | 57 | public function offsetSet($id, $value) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Gets a parameter or an object. |
||
| 94 | * |
||
| 95 | * @param string $id The unique identifier for the parameter or object. |
||
| 96 | * |
||
| 97 | * @return mixed The value of the parameter or an object |
||
| 98 | * @throws \InvalidArgumentException If the identifier is not defined. |
||
| 99 | */ |
||
| 100 | 48 | public function offsetGet($id) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Checks if a parameter or an object is set. |
||
| 129 | * |
||
| 130 | * @param string $id The unique identifier for the parameter or object. |
||
| 131 | * |
||
| 132 | * @return boolean |
||
| 133 | */ |
||
| 134 | 4 | public function offsetExists($id) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Unsets a parameter or an object. |
||
| 141 | * |
||
| 142 | * @param string $id The unique identifier for the parameter or object. |
||
| 143 | * |
||
| 144 | * @return void |
||
| 145 | */ |
||
| 146 | 9 | public function offsetUnset($id) |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Marks a callable as being a factory service. |
||
| 159 | * |
||
| 160 | * @param callable $callable A service definition to be used as a factory. |
||
| 161 | * |
||
| 162 | * @return callable The passed callable |
||
| 163 | * @throws \InvalidArgumentException Service definition has to be a closure of an invokable object. |
||
| 164 | */ |
||
| 165 | 34 | public function factory($callable) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Protects a callable from being interpreted as a service. |
||
| 178 | * |
||
| 179 | * This is useful when you want to store a callable as a parameter. |
||
| 180 | * |
||
| 181 | * @param callable $callable A callable to protect from being evaluated. |
||
| 182 | * |
||
| 183 | * @return callable The passed callable |
||
| 184 | * @throws \InvalidArgumentException Service definition has to be a closure of an invokable object. |
||
| 185 | */ |
||
| 186 | 4 | public function protect($callable) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Gets a parameter or the closure defining an object. |
||
| 199 | * |
||
| 200 | * @param string $id The unique identifier for the parameter or object. |
||
| 201 | * |
||
| 202 | * @return mixed The value of the parameter or the closure defining an object |
||
| 203 | * @throws \InvalidArgumentException If the identifier is not defined. |
||
| 204 | */ |
||
| 205 | 4 | public function raw($id) |
|
| 217 | |||
| 218 | /** |
||
| 219 | * Extends an object definition. |
||
| 220 | * |
||
| 221 | * Useful when you want to extend an existing object definition, |
||
| 222 | * without necessarily loading that object. |
||
| 223 | * |
||
| 224 | * @param string $id The unique identifier for the object. |
||
| 225 | * @param callable $callable A service definition to extend the original. |
||
| 226 | * |
||
| 227 | * @return callable The wrapped callable |
||
| 228 | * @throws \InvalidArgumentException If the identifier is not defined or not a service definition. |
||
| 229 | */ |
||
| 230 | 10 | public function extend($id, $callable) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * Returns all defined value names. |
||
| 260 | * |
||
| 261 | * @return array An array of value names |
||
| 262 | */ |
||
| 263 | 1 | public function keys() |
|
| 267 | |||
| 268 | /** |
||
| 269 | * Registers a service provider. |
||
| 270 | * |
||
| 271 | * @param ServiceProviderInterface $provider A ServiceProviderInterface instance. |
||
| 272 | * @param array $values An array of values that customizes the provider. |
||
| 273 | * |
||
| 274 | * @return static |
||
| 275 | */ |
||
| 276 | 2 | public function register(ServiceProviderInterface $provider, array $values = array()) |
|
| 286 | |||
| 287 | } |
||
| 288 |