Container
class Container implements ContainerInterface, ArrayAccess (View source)
Dependency Injection Container that supports different types of values.
Constants
| TYPE_VALUE |
Type for value entries |
| TYPE_STANDARD |
Type for standard entries |
| TYPE_BLUEPRINT |
Type for blueprint entries |
| TYPE_FACTORY |
Type for factory entries |
Methods
Container constructor.
Sets new standard entries.
Sets new value entries.
Sets new blueprint entries.
Sets new factory entries.
Adds additional injections for blueprints.
Returns a container entry based on a given dot path.
Returns the entry with the given identifier.
Tells if the container has an entry with the given identifier.
Tells if the container has an entry with the given identifier.
Returns the value for entry with the given identifier.
Sets the value of the standard entry with the given identifier.
Removes the entry from the container with the given identifier.
Details
at line 51
__construct(ContainerInterface $delegate = null)
Container constructor.
at line 87
$this
set(array $values)
Sets new standard entries.
A standard entry may either be a plain PHP value or an invokable. If an invokable is provided, that invokable is called with the container as a parameter and the return value is used as the value for the entry. Note that value returned by the invokable is cached and the same value is returned for further requests for that entry.
at line 102
$this
setValues(array $values)
Sets new value entries.
A value entry is any PHP value and is simply returned as is when requested, even if the provided value is an invokable.
at line 137
$this
setBlueprints(array $blueprints)
Sets new blueprint entries.
A blueprint entry is an instruction on how to create a new instance as the value for the entry. The blueprint entry must be an an array that defines how to instantiate a class.
The name of the class may be provided via a key labeled class. If no
such key exists, then the entry identifier itself is used as the name of
the class.
The constructor arguments for the instance can be provided via a key
labeled __construct. However, if neither class nor __construct keys
exist in the array, The values of the array are used as the constructor
arguments.
Additional methods for the instance may be called by defining additional values to the array. If the key of the value is a string, then that string is used as the name of the method to call and the value, which must be an array, as the arguments for the method. However, for integer keys, the value must be an array that defines the name of the method as the first value and the arguments in the rest of the values.
Please note that argument values MUST be identifiers for container entries.
at line 154
$this
setFactories(array $factories)
Sets new factory entries.
A factory entry is simply a callable that is always called to determine the value for the entry (in comparison to a standard entry, which is only called once). Factories may be any kind of callables and the callable is always called with the container as the parameter.
at line 199
$this
setInjections(array $injections)
Adds additional injections for blueprints.
Injections are additional method calls for blueprints. Each key in the provided array defines either a class or an interface. If any instance is created via a blueprint and it implements or extends any of these keys, the additional method calls for the key are also called for the instance.
The injection method calls are defined the same way as additional method calls in blueprints.
at line 233
mixed
getPath(string $path, mixed $default = null)
Returns a container entry based on a given dot path.
The doth path is a period separated string, which indicates the entry identifier and the keys of further traversed values. The traversed values may be additional containers, arrays or objects with or without array access. For example, assuming the entry is an array, the following two would be equivalent:
$container->get('config')['session']['name']$container->getPath('config.session.name')
Note that if a delegate container has been set, the initial lookup is performed on the delegate container.
This method also allows providing a default value that is returned when the provided path cannot be found within the container. If no default value has been provided, an exception will be thrown instead.
at line 254
mixed
get(string $id)
Returns the entry with the given identifier.
at line 363
bool
has(string $id)
Tells if the container has an entry with the given identifier.
at line 373
bool
offsetExists(string $offset)
Tells if the container has an entry with the given identifier.
at line 384
mixed
offsetGet(string $offset)
Returns the value for entry with the given identifier.
at line 394
offsetSet(string $offset, mixed $value)
Sets the value of the standard entry with the given identifier.
at line 404
offsetUnset(string $offset)
Removes the entry from the container with the given identifier.