Drupal 8  8.0.2
Inheritance diagram for Container:

Public Member Functions

 __construct (array $container_definition=array())
 
 get ($id, $invalid_behavior=ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
 
 set ($id, $service, $scope=ContainerInterface::SCOPE_CONTAINER)
 
 has ($id)
 
 getParameter ($name)
 
 hasParameter ($name)
 
 setParameter ($name, $value)
 
 initialized ($id)
 
 enterScope ($name)
 
 leaveScope ($name)
 
 addScope (ScopeInterface $scope)
 
 hasScope ($name)
 
 isScopeActive ($name)
 
 getServiceIds ()
 

Protected Member Functions

 createService (array $definition, $id)
 
 resolveServicesAndParameters ($arguments)
 
 getAlternatives ($search_key, array $keys)
 
 getServiceAlternatives ($id)
 
 getParameterAlternatives ($name)
 

Protected Attributes

 $parameters = array()
 
 $aliases = array()
 
 $serviceDefinitions = array()
 
 $services = array()
 
 $privateServices = array()
 
 $loading = array()
 
 $frozen = TRUE
 

Detailed Description

Provides a container optimized for Drupal's needs.

This container implementation is compatible with the default Symfony dependency injection container and similar to the Symfony ContainerBuilder class, but optimized for speed.

It is based on a PHP array container definition dumped as a performance-optimized machine-readable format.

The best way to initialize this container is to use a Container Builder, compile it and then retrieve the definition via ::getArray().

The retrieved array can be cached safely and then passed to this container via the constructor.

As the container is unfrozen by default, a second parameter can be passed to the container to "freeze" the parameter bag.

This container is different in behavior from the default Symfony container in the following ways:

  • It only allows lowercase service and parameter names, though it does only enforce it via assertions for performance reasons.
  • The following functions, that are not part of the interface, are explicitly not supported: getParameterBag(), isFrozen(), compile(), getAServiceWithAnIdByCamelCase().
  • The function getServiceIds() was added as it has a use-case in core and contrib.
  • Scopes are explicitly not allowed, because Symfony 2.8 has deprecated them and they will be removed in Symfony 3.0.
  • Synchronized services are explicitly not supported, because Symfony 2.8 has deprecated them and they will be removed in Symfony 3.0.

Constructor & Destructor Documentation

__construct ( array  $container_definition = array())

Constructs a new Container instance.

Parameters
array$container_definitionAn array containing the following keys:
  • aliases: The aliases of the container.
  • parameters: The parameters of the container.
  • services: The service definitions of the container.
  • frozen: Whether the container definition came from a frozen container builder or not.
  • machine_format: Whether this container definition uses the optimized machine-readable container format.

Member Function Documentation

addScope ( ScopeInterface  $scope)

{}

createService ( array  $definition,
  $id 
)
protected

Creates a service from a service definition.

Parameters
array$definitionThe service definition to create a service from.
string$idThe service identifier, necessary so it can be shared if its public.
Returns
object The service described by the service definition.
Exceptions
\Symfony\Component\DependencyInjection\Exception\RuntimeExceptionThrown when the service is a synthetic service.
\Symfony\Component\DependencyInjection\Exception\InvalidArgumentExceptionThrown when the configurator callable in $definition['configurator'] is not actually a callable.
\ReflectionExceptionThrown when the service class takes more than 10 parameters to construct, and cannot be instantiated.

References Container\resolveServicesAndParameters().

Referenced by Container\get().

Here is the call graph for this function:

Here is the caller graph for this function:

enterScope (   $name)

{}

get (   $id,
  $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE 
)

{}

References Container\createService(), and Container\getServiceAlternatives().

Here is the call graph for this function:

getAlternatives (   $search_key,
array  $keys 
)
protected

Provides alternatives for a given array and key.

Parameters
string$search_keyThe search key to get alternatives for.
array$keysThe search space to search for alternatives in.
Returns
string[] An array of strings with suitable alternatives.
getParameter (   $name)

{}

getParameterAlternatives (   $name)
protected

Provides alternatives in case a parameter was not found.

Parameters
string$nameThe parameter to get alternatives for.
Returns
string[] An array of strings with suitable alternatives.
getServiceAlternatives (   $id)
protected

Provides alternatives in case a service was not found.

Parameters
string$idThe service to get alternatives for.
Returns
string[] An array of strings with suitable alternatives.

Referenced by Container\get().

Here is the caller graph for this function:

getServiceIds ( )

Gets all defined service IDs.

Returns
array An array of all defined service IDs.
has (   $id)

{}

hasParameter (   $name)

{}

hasScope (   $name)

{}

initialized (   $id)

{}

isScopeActive (   $name)

{}

leaveScope (   $name)

{}

resolveServicesAndParameters (   $arguments)
protected

Resolves arguments that represent services or variables to the real values.

Parameters
array | \stdClass$argumentsThe arguments to resolve.
Returns
array The resolved arguments.
Exceptions
\Symfony\Component\DependencyInjection\Exception\RuntimeExceptionIf a parameter/service could not be resolved.
\Symfony\Component\DependencyInjection\Exception\InvalidArgumentExceptionIf an unknown type is met while resolving parameters and services.

Referenced by Container\createService().

Here is the caller graph for this function:

set (   $id,
  $service,
  $scope = ContainerInterface::SCOPE_CONTAINER 
)

{}

setParameter (   $name,
  $value 
)

{}


The documentation for this class was generated from the following file: