Container
in package
implements
ContainerInterface, ResetInterface
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 at compilation time (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
- RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at runtime
Tags
Interfaces, Classes and Traits
- ContainerInterface
- ContainerInterface is the interface implemented by service container classes.
- ResetInterface
- Provides a way to reset an object to its initial state.
Table of Contents
- $aliases : mixed
- $factories : mixed
- $fileMap : mixed
- $loading : mixed
- $methodMap : mixed
- $parameterBag : mixed
- $privates : mixed
- $resolving : mixed
- $services : mixed
- $syntheticIds : mixed
- $compiled : mixed
- $envCache : mixed
- $getEnv : mixed
- __construct() : mixed
- camelize() : string
- Camelizes a string.
- compile() : mixed
- Compiles the container.
- get() : object|null
- Gets a service.
- getParameter() : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
- Gets a parameter.
- getParameterBag() : ParameterBagInterface
- Gets the service container parameter bag.
- getRemovedIds() : array<string|int, mixed>
- Gets service ids that existed at compile time.
- getServiceIds() : array<string|int, string>
- Gets all service ids.
- has() : bool
- Returns true if the given service is defined.
- hasParameter() : bool
- initialized() : bool
- Returns true if the given service has actually been initialized.
- isCompiled() : bool
- Returns true if the container is compiled.
- reset() : mixed
- set() : mixed
- Sets a service.
- setParameter() : mixed
- Sets a parameter.
- underscore() : string
- A string to underscore.
- getEnv() : mixed
- Fetches a variable from the environment.
- load() : mixed
- Creates a service by requiring its factory file.
- __clone() : mixed
- make() : mixed
- Creates a service.
Properties
$aliases
protected
mixed
$aliases
= []
$factories
protected
mixed
$factories
= []
$fileMap
protected
mixed
$fileMap
= []
$loading
protected
mixed
$loading
= []
$methodMap
protected
mixed
$methodMap
= []
$parameterBag
protected
mixed
$parameterBag
$privates
protected
mixed
$privates
= []
$resolving
protected
mixed
$resolving
= []
$services
protected
mixed
$services
= []
$syntheticIds
protected
mixed
$syntheticIds
= []
$compiled
private
mixed
$compiled
= false
$envCache
private
mixed
$envCache
= []
$getEnv
private
mixed
$getEnv
Methods
__construct()
public
__construct([ParameterBagInterface|null $parameterBag = null ]) : mixed
Parameters
- $parameterBag : ParameterBagInterface|null = null
Return values
mixed —camelize()
Camelizes a string.
public
static camelize(string $id) : string
Parameters
- $id : string
Return values
string —compile()
Compiles the container.
public
compile() : mixed
This method does two things:
- Parameter values are resolved;
- The parameter bag is frozen.
Return values
mixed —get()
Gets a service.
public
get(string $id[, int $invalidBehavior = 1 ]) : object|null
Parameters
- $id : string
-
The service identifier
- $invalidBehavior : int = 1
-
The behavior when the service does not exist
Tags
Return values
object|null —getParameter()
Gets a parameter.
public
getParameter(string $name) : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
Parameters
- $name : string
Tags
Return values
array<string|int, mixed>|bool|string|int|float|UnitEnum|null —getParameterBag()
Gets the service container parameter bag.
public
getParameterBag() : ParameterBagInterface
Return values
ParameterBagInterface —getRemovedIds()
Gets service ids that existed at compile time.
public
getRemovedIds() : array<string|int, mixed>
Return values
array<string|int, mixed> —getServiceIds()
Gets all service ids.
public
getServiceIds() : array<string|int, string>
Return values
array<string|int, string> —has()
Returns true if the given service is defined.
public
has(string $id) : bool
Parameters
- $id : string
-
The service identifier
Return values
bool —hasParameter()
public
hasParameter(string $name) : bool
Parameters
- $name : string
Return values
bool —initialized()
Returns true if the given service has actually been initialized.
public
initialized(string $id) : bool
Parameters
- $id : string
Return values
bool —isCompiled()
Returns true if the container is compiled.
public
isCompiled() : bool
Return values
bool —reset()
public
reset() : mixed
Return values
mixed —set()
Sets a service.
public
set(string $id, object|null $service) : mixed
Setting a synthetic service to null resets it: has() returns false and get() behaves in the same way as if the service was never created.
Parameters
- $id : string
- $service : object|null
Return values
mixed —setParameter()
Sets a parameter.
public
setParameter(string $name, array<string|int, mixed>|bool|string|int|float|UnitEnum|null $value) : mixed
Parameters
- $name : string
-
The parameter name
- $value : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
-
The parameter value
Return values
mixed —underscore()
A string to underscore.
public
static underscore(string $id) : string
Parameters
- $id : string
Return values
string —getEnv()
Fetches a variable from the environment.
protected
getEnv(string $name) : mixed
Parameters
- $name : string
Tags
Return values
mixed —load()
Creates a service by requiring its factory file.
protected
load(string $file) : mixed
Parameters
- $file : string
Return values
mixed —__clone()
private
__clone() : mixed
Return values
mixed —make()
Creates a service.
private
make(string $id, int $invalidBehavior) : mixed
As a separate method to allow "get()" to use the really fast ??
operator.
Parameters
- $id : string
- $invalidBehavior : int