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:

Throws

RuntimeException When trying to set a service in an inactive scope

InvalidArgumentException When trying to set a service in the prototype scope

Overrides ContainerInterface::set

6 calls to Container::set()
Container::leaveScope in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php
This is called to leave the current scope, and move back to the parent scope.
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.

... See full list

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 195

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(sprintf('You cannot set service "%s" of scope "prototype".', $id));
  }
  $id = strtolower($id);
  if (self::SCOPE_CONTAINER !== $scope) {
    if (!isset($this->scopedServices[$scope])) {
      throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
    }
    $this->scopedServices[$scope][$id] = $service;
  }
  $this->services[$id] = $service;
  if (method_exists($this, $method = 'synchronize' . strtr($id, array(
    '_' => '',
    '.' => '_',
  )) . 'Service')) {
    $this
      ->{$method}();
  }
}