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()
1 method overrides Container::set()

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;
}