class Container implements IntrospectableContainerInterface
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
|
__construct(ParameterBagInterface $parameterBag = null)
Constructor. |
||
|
compile()
Compiles the container. |
||
| Boolean |
isFrozen()
Returns true if the container parameter bag are frozen. |
|
| ParameterBagInterface |
getParameterBag()
Gets the service container parameter bag. |
|
| mixed |
getParameter(string $name)
Gets a parameter. |
|
| Boolean |
hasParameter(string $name)
Checks if a parameter exists. |
|
|
setParameter(string $name, mixed $value)
Sets a parameter. |
||
|
set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)
Sets a service. |
||
| Boolean |
has(string $id)
Returns true if the given service is defined. |
|
| object |
get(string $id, integer $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service. |
|
| Boolean |
initialized(string $id)
Returns true if the given service has actually been initialized |
|
| array |
getServiceIds()
Gets all service ids. |
|
|
enterScope(string $name)
This is called when you enter a scope |
||
|
leaveScope(string $name)
This is called to leave the current scope, and move back to the parent scope. |
||
|
addScope(ScopeInterface $scope)
Adds a scope to the container. |
||
| Boolean |
hasScope(string $name)
Returns whether this container has a certain scope |
|
| Boolean |
isScopeActive(string $name)
Returns whether this scope is currently active |
|
| static string |
camelize(string $id)
Camelizes a string. |
|
| static string |
underscore(string $id)
A string to underscore. |
Details
at line 86
public
__construct(ParameterBagInterface $parameterBag = null)
Constructor.
at line 109
public
compile()
Compiles the container.
This method does two things:
- Parameter values are resolved;
- The parameter bag is frozen.
at line 123
public Boolean
isFrozen()
Returns true if the container parameter bag are frozen.
at line 135
public ParameterBagInterface
getParameterBag()
Gets the service container parameter bag.
at line 151
public mixed
getParameter(string $name)
Gets a parameter.
at line 165
public Boolean
hasParameter(string $name)
Checks if a parameter exists.
at line 178
public
setParameter(string $name, mixed $value)
Sets a parameter.
at line 195
public
set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)
Sets a service.
at line 227
public Boolean
has(string $id)
Returns true if the given service is defined.
at line 253
public object
get(string $id, integer $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 325
public Boolean
initialized(string $id)
Returns true if the given service has actually been initialized
at line 335
public array
getServiceIds()
Gets all service ids.
at line 358
public
enterScope(string $name)
This is called when you enter a scope
at line 406
public
leaveScope(string $name)
This is called to leave the current scope, and move back to the parent scope.
at line 448
public
addScope(ScopeInterface $scope)
Adds a scope to the container.
at line 482
public Boolean
hasScope(string $name)
Returns whether this container has a certain scope
at line 498
public Boolean
isScopeActive(string $name)
Returns whether this scope is currently active
This does not actually check if the passed scope actually exists.
at line 510
static public string
camelize(string $id)
Camelizes a string.
at line 522
static public string
underscore(string $id)
A string to underscore.