function Container::__construct

Same name and namespace in other branches
  1. 7.x misc/typo3/phar-stream-wrapper/src/Phar/Container.php \TYPO3\PharStreamWrapper\Phar\Container::__construct()
  2. 8.9.x core/lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container::__construct()
  3. 10 core/lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container::__construct()
  4. 11.x core/lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container::__construct()

Constructs a new Container instance.

Parameters

array $container_definition: An 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.
1 method overrides Container::__construct()
PhpArrayContainer::__construct in core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php
Constructs a new Container instance.

File

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

Class

Container
Provides a container optimized for Drupal's needs.

Namespace

Drupal\Component\DependencyInjection

Code

public function __construct(array $container_definition = []) {
    if (!empty($container_definition) && (!isset($container_definition['machine_format']) || $container_definition['machine_format'] !== TRUE)) {
        throw new InvalidArgumentException('The non-optimized format is not supported by this class. Use an optimized machine-readable format instead, e.g. as produced by \\Drupal\\Component\\DependencyInjection\\Dumper\\OptimizedPhpArrayDumper.');
    }
    $this->aliases = $container_definition['aliases'] ?? [];
    $this->parameters = $container_definition['parameters'] ?? [];
    $this->serviceDefinitions = $container_definition['services'] ?? [];
    $this->frozen = $container_definition['frozen'] ?? FALSE;
    // Register the service_container with itself.
    $this->services['service_container'] = $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.