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 (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
Tags
Table of Contents
Interfaces
- ContainerInterface
- ContainerInterface is the interface implemented by service container classes.
- ResetInterface
- Provides a way to reset an object to its initial state.
Properties
- $aliases : mixed
- $factories : mixed
- $fileMap : mixed
- $loading : mixed
- $methodMap : mixed
- $parameterBag : mixed
- $privates : mixed
- $resolving : mixed
- $services : mixed
- $syntheticIds : mixed
- $compiled : bool
- $envCache : array<string|int, mixed>
- $getEnv : Closure
Methods
- __construct() : mixed
- camelize() : string
- Camelizes a string.
- compile() : mixed
- Compiles the container.
- get() : mixed
- 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 container can return an entry for the given identifier.
- 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
- 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
bool
$compiled
= false
$envCache
private
array<string|int, mixed>
$envCache
= []
$getEnv
private
Closure
$getEnv
Methods
__construct()
public
__construct([ParameterBagInterface $parameterBag = null ]) : mixed
Parameters
- $parameterBag : ParameterBagInterface = null
camelize()
Camelizes a string.
public
static camelize(string $id) : string
Parameters
- $id : string
Return values
stringcompile()
Compiles the container.
public
compile() : mixed
This method does two things:
- Parameter values are resolved;
- The parameter bag is frozen.
get()
Gets a service.
public
get(string $id[, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE ]) : mixed
Parameters
- $id : string
-
Identifier of the entry to look for.
- $invalidBehavior : int = self::EXCEPTION_ON_INVALID_REFERENCE
Tags
Return values
mixed —Entry.
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|nullgetParameterBag()
Gets the service container parameter bag.
public
getParameterBag() : ParameterBagInterface
Return values
ParameterBagInterfacegetRemovedIds()
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 container can return an entry for the given identifier.
public
has(string $id) : bool
Returns false otherwise.
has($id)
returning true does not mean that get($id)
will not throw an exception.
It does however mean that get($id)
will not throw a NotFoundExceptionInterface
.
Parameters
- $id : string
-
Identifier of the entry to look for.
Return values
boolhasParameter()
public
hasParameter(string $name) : bool
Parameters
- $name : string
Return values
boolinitialized()
Returns true if the given service has actually been initialized.
public
initialized(string $id) : bool
Parameters
- $id : string
Return values
boolisCompiled()
Returns true if the container is compiled.
public
isCompiled() : bool
Return values
boolreset()
public
reset() : 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
setParameter()
public
setParameter(string $name, array<string|int, mixed>|bool|string|int|float|UnitEnum|null $value) : mixed
Parameters
- $name : string
- $value : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
underscore()
A string to underscore.
public
static underscore(string $id) : string
Parameters
- $id : string
Return values
stringgetEnv()
Fetches a variable from the environment.
protected
getEnv(string $name) : mixed
Parameters
- $name : string
Tags
load()
Creates a service by requiring its factory file.
protected
load(string $file) : mixed
Parameters
- $file : string
__clone()
private
__clone() : 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