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.
Parameter and service keys are case insensitive.
A service id can contain lowercased letters, digits, underscores, and dots. Underscores are used to separate words, and dots to group services under namespaces:
- request
- mysql_session_storage
- symfony.mysql_session_storage
A service can also be defined by creating a method named getXXXService(), where XXX is the camelized version of the id:
- request -> getRequestService()
- mysql_session_storage -> getMysqlSessionStorageService()
- symfony.mysql_session_storage -> getSymfony_MysqlSessionStorageService()
The container can have three possible behaviors when a service does not exist:
- EXCEPTIONONINVALID_REFERENCE: Throws an exception (the default)
- NULLONINVALID_REFERENCE: Returns null
- IGNOREONINVALID_REFERENCE: Ignores the wrapping command asking for the reference (for instance, ignore a setter if the service does not exist)
Methods
Compiles the container.
Returns true if the container parameter bag are frozen.
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.
Camelizes a string.
A string to underscore.
Details
at line line 78
__construct(ParameterBagInterface $parameterBag = null)
Constructor.
at line line 91
compile()
Compiles the container.
This method does two things:
- Parameter values are resolved;
- The parameter bag is frozen.
at line line 103
bool
isFrozen()
Returns true if the container parameter bag are frozen.
at line line 113
ParameterBagInterface
getParameterBag()
Gets the service container parameter bag.
at line line 127
mixed
getParameter(string $name)
Gets a parameter.
at line line 139
bool
hasParameter(string $name)
Checks if a parameter exists.
at line line 150
setParameter(string $name, mixed $value)
Sets a parameter.
at line line 164
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.
at line line 186
bool
has(string $id)
Returns true if the given service is defined.
at line line 221
object
get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service.
If a service is defined both through a set() method and with a get{$id}Service() method, the former has always precedence.
at line line 293
bool
initialized(string $id)
Returns true if the given service has actually been initialized.
at line line 311
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.
at line line 321
array
getServiceIds()
Gets all service ids.
at line line 342
static string
camelize(string $id)
Camelizes a string.
at line line 354
static string
underscore(string $id)
A string to underscore.