public function Container::set

Sets a service.

@api

Parameters

string $id The service identifier:

object $service The service instance:

string $scope The scope of the service:

Overrides ContainerInterface::set

4 calls to Container::set()
Container::__construct in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php
Constructor.
ContainerBuilder::set in drupal/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().
ContainerBuilder::set in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Sets a service.
ProjectServiceContainer::__construct in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php
Constructor.
1 method overrides Container::set()
ContainerBuilder::set in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Sets a service.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php, line 185

Class

Container
Container is a dependency injection container.

Namespace

Symfony\Component\DependencyInjection

Code

public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
  if (self::SCOPE_PROTOTYPE === $scope) {
    throw new InvalidArgumentException('You cannot set services of scope "prototype".');
  }
  $id = strtolower($id);
  if (self::SCOPE_CONTAINER !== $scope) {
    if (!isset($this->scopedServices[$scope])) {
      throw new RuntimeException('You cannot set services of inactive scopes.');
    }
    $this->scopedServices[$scope][$id] = $service;
  }
  $this->services[$id] = $service;
}