Container

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 \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::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.

Hierarchy

  • class \Drupal\Component\DependencyInjection\Container implements IntrospectableContainerInterface, ResettableContainerInterface

Related topics

Services and Dependency Injection Container
Overview of the Dependency Injection Container and Services.

File

core/lib/Drupal/Component/DependencyInjection/Container.php, line 53

Namespace

Drupal\Component\DependencyInjection

Members

Name Modifiers Type Description
Container::$aliases protected property The aliases of the container.
Container::$frozen protected property Whether the container parameters can still be changed.
Container::$loading protected property The currently loading services.
Container::$parameters protected property The parameters of the container.
Container::$privateServices protected property The instantiated private services.
Container::$serviceDefinitions protected property The service definitions of the container.
Container::$services protected property The instantiated services.
Container::addScope public function
Container::createService protected function Creates a service from a service definition.
Container::enterScope public function
Container::get public function
Container::getAlternatives protected function Provides alternatives for a given array and key.
Container::getParameter public function
Container::getParameterAlternatives protected function Provides alternatives in case a parameter was not found.
Container::getServiceAlternatives protected function Provides alternatives in case a service was not found.
Container::getServiceIds public function Gets all defined service IDs.
Container::has public function
Container::hasParameter public function
Container::hasScope public function
Container::initialized public function Check for whether or not a service has been initialized. Overrides IntrospectableContainerInterface::initialized
Container::isScopeActive public function
Container::leaveScope public function
Container::reset public function Resets shared services from the container. Overrides ResettableContainerInterface::reset
Container::resolveServicesAndParameters protected function Resolves arguments that represent services or variables to the real values.
Container::set public function
Container::setParameter public function
Container::__clone private function Ensure that cloning doesn't work.
Container::__construct public function Constructs a new Container instance.
doc_Drupal
2016-10-29 08:56:34
Comments
Leave a Comment

Please login to continue.