Container
class Container implements ResettableContainerInterface
Container is a dependency injection container.
It gives access to object instances (services). Services and parameters are simple key/pair stores. The container can have four possible behaviors when a service does not exist (or is not initialized for the last case):
- EXCEPTION_ON_INVALID_REFERENCE: Throws an exception (the default)
- NULL_ON_INVALID_REFERENCE: Returns null
- IGNORE_ON_INVALID_REFERENCE: Ignores the wrapping command asking for the reference (for instance, ignore a setter if the service does not exist)
- IGNORE_ON_UNINITIALIZED_REFERENCE: Ignores/returns null for uninitialized services or invalid references
Properties
Methods
Compiles the container.
Returns true if the container is compiled.
Gets the service container parameter bag.
Gets a parameter.
Checks if a parameter exists.
Sets a parameter.
Sets a service.
Returns true if the given service is defined.
Gets a service.
Returns true if the given service has actually been initialized.
Resets shared services from the container.
Gets all service ids.
Gets service ids that existed at compile time.
Camelizes a string.
A string to underscore.
Creates a service by requiring its factory file.
Fetches a variable from the environment.
No description
Details
compile()
Compiles the container.
This method does two things:
- Parameter values are resolved;
- The parameter bag is frozen.
set(string $id, object $service)
Sets a service.
Setting a service to null resets the service: has() returns false and get() behaves in the same way as if the service was never created.
reset()
Resets shared services from the container.
The container is not intended to be used again after being reset in a normal workflow. This method is meant as a way to release references for ref-counting. A subsequent call to ContainerInterface::get will recreate a new instance of the shared service.