Symfony2 API
Interface

Symfony\Component\DependencyInjection\ContainerInterface

interface ContainerInterface

ContainerInterface is the interface implemented by service container classes.

Constants

EXCEPTION_ON_INVALID_REFERENCE

NULL_ON_INVALID_REFERENCE

IGNORE_ON_INVALID_REFERENCE

SCOPE_CONTAINER

SCOPE_PROTOTYPE

Methods

set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)

Sets a service.

object get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)

Gets a service.

bool has(string $id)

Returns true if the given service is defined.

mixed getParameter(string $name)

Gets a parameter.

bool hasParameter(string $name)

Checks if a parameter exists.

setParameter(string $name, mixed $value)

Sets a parameter.

enterScope(string $name)

Enters the given scope

leaveScope(string $name)

Leaves the current scope, and re-enters the parent scope

addScope(ScopeInterface $scope)

Adds a scope to the container

bool hasScope(string $name)

Whether this container has the given scope

bool isScopeActive(string $name)

Determines whether the given scope is currently active.

Details

at line 43
public set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)

Sets a service.

Parameters

string $id The service identifier
object $service The service instance
string $scope The scope of the service

at line 61
public object get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)

Gets a service.

Parameters

string $id The service identifier
int $invalidBehavior The behavior when the service does not exist

Return Value

object The associated service

Exceptions

InvalidArgumentException if the service is not defined
ServiceCircularReferenceException When a circular reference is detected
ServiceNotFoundException When the service is not defined

See also

Reference

at line 72
public bool has(string $id)

Returns true if the given service is defined.

Parameters

string $id The service identifier

Return Value

bool true if the service is defined, false otherwise

at line 85
public mixed getParameter(string $name)

Gets a parameter.

Parameters

string $name The parameter name

Return Value

mixed The parameter value

Exceptions

InvalidArgumentException if the parameter is not defined

at line 96
public bool hasParameter(string $name)

Checks if a parameter exists.

Parameters

string $name The parameter name

Return Value

bool The presence of parameter in container

at line 106
public setParameter(string $name, mixed $value)

Sets a parameter.

Parameters

string $name The parameter name
mixed $value The parameter value

at line 115
public enterScope(string $name)

Enters the given scope

Parameters

string $name

at line 124
public leaveScope(string $name)

Leaves the current scope, and re-enters the parent scope

Parameters

string $name

at line 133
public addScope(ScopeInterface $scope)

Adds a scope to the container

Parameters

ScopeInterface $scope

at line 144
public bool hasScope(string $name)

Whether this container has the given scope

Parameters

string $name

Return Value

bool

at line 157
public bool isScopeActive(string $name)

Determines whether the given scope is currently active.

It does however not check if the scope actually exists.

Parameters

string $name

Return Value

bool