class Container implements ArrayAccess, ContainerInterface

Container main class.

Methods

__construct(array $values = array())

Instantiate the container.

build($class, $parameters = array())

No description

bool
has($id)

No description

mixed
get($id)

No description

$this
set($id, $value)

No description

$this
addAlias($name, $id)

No description

$this
getAlias($name)

No description

hasAlias($name)

No description

$this
removeAlias($name)

No description

$this
remove($name)

No description

offsetSet(string $id, mixed $value)

Sets a parameter or an object.

mixed
offsetGet(string $id)

Gets a parameter or an object.

bool
offsetExists(string $id)

Checks if a parameter or an object is set.

offsetUnset(string $id)

Unsets a parameter or an object.

callable
factory(callable $callable)

Marks a callable as being a factory service.

callable
protect(callable $callable)

Protects a callable from being interpreted as a service.

mixed
raw(string $id)

Gets a parameter or the closure defining an object.

callable
extend(string $id, callable $callable)

Extends an object definition.

array
keys()

Returns all defined value names.

register(ServiceProviderInterface $provider, array $values = array())

Registers a service provider.

$this
tag(string $id, string $tag)

Tag a service

array
findTaggedServiceIds(string $tag)

Find all service ids with a given tag

array
getServiceTags()

Get all service tags

Details

at line 77
__construct(array $values = array())

Instantiate the container.

Objects and parameters can be passed as argument to the constructor.

Parameters

array $values The parameters or objects.

at line 87
build($class, $parameters = array())

Parameters

$class
$parameters

at line 194
bool has($id)

Parameters

$id

Return Value

bool

at line 203
mixed get($id)

Parameters

$id

Return Value

mixed

at line 213
$this set($id, $value)

Parameters

$id
$value

Return Value

$this

at line 225
$this addAlias($name, $id)

Parameters

$name
$id

Return Value

$this

at line 235
$this getAlias($name)

Parameters

$name

Return Value

$this

at line 240
hasAlias($name)

Parameters

$name

at line 249
$this removeAlias($name)

Parameters

$name

Return Value

$this

at line 259
$this remove($name)

Parameters

$name

Return Value

$this

at line 278
offsetSet(string $id, mixed $value)

Sets a parameter or an object.

Objects must be defined as Closures.

Allowing any PHP callable leads to difficult to debug problems as function names (strings) are callable (creating a function with the same name as an existing parameter would break your container).

Parameters

string $id The unique identifier for the parameter or object
mixed $value The value of the parameter or a closure to define an object

Exceptions

RuntimeException Prevent override of a frozen service

at line 298
mixed offsetGet(string $id)

Gets a parameter or an object.

Parameters

string $id The unique identifier for the parameter or object

Return Value

mixed The value of the parameter or an object

Exceptions

InvalidArgumentException if the identifier is not defined

at line 341
bool offsetExists(string $id)

Checks if a parameter or an object is set.

Parameters

string $id The unique identifier for the parameter or object

Return Value

bool

at line 355
offsetUnset(string $id)

Unsets a parameter or an object.

Parameters

string $id The unique identifier for the parameter or object

at line 381
callable factory(callable $callable)

Marks a callable as being a factory service.

Parameters

callable $callable A service definition to be used as a factory

Return Value

callable The passed callable

Exceptions

InvalidArgumentException Service definition has to be a closure of an invokable object

at line 403
callable protect(callable $callable)

Protects a callable from being interpreted as a service.

This is useful when you want to store a callable as a parameter.

Parameters

callable $callable A callable to protect from being evaluated

Return Value

callable The passed callable

Exceptions

InvalidArgumentException Service definition has to be a closure of an invokable object

at line 423
mixed raw(string $id)

Gets a parameter or the closure defining an object.

Parameters

string $id The unique identifier for the parameter or object

Return Value

mixed The value of the parameter or the closure defining an object

Exceptions

InvalidArgumentException if the identifier is not defined

at line 449
callable extend(string $id, callable $callable)

Extends an object definition.

Useful when you want to extend an existing object definition, without necessarily loading that object.

Parameters

string $id The unique identifier for the object
callable $callable A service definition to extend the original

Return Value

callable The wrapped callable

Exceptions

InvalidArgumentException if the identifier is not defined or not a service definition

at line 483
array keys()

Returns all defined value names.

Return Value

array An array of value names

at line 496
Container register(ServiceProviderInterface $provider, array $values = array())

Registers a service provider.

Parameters

ServiceProviderInterface $provider A ServiceProviderInterface instance
array $values An array of values that customizes the provider

Return Value

Container

at line 514
$this tag(string $id, string $tag)

Tag a service

Parameters

string $id
string $tag

Return Value

$this

at line 530
array findTaggedServiceIds(string $tag)

Find all service ids with a given tag

Parameters

string $tag

Return Value

array

at line 548
array getServiceTags()

Get all service tags

Return Value

array