public function ContainerBuilder::set

Same name in this branch

Sets a service.

@api

Parameters

string $id The service identifier:

object $service The service instance:

string $scope The scope:

Throws

BadMethodCallException When this ContainerBuilder is frozen

Overrides Container::set

1 method overrides ContainerBuilder::set()
ContainerBuilder::set in drupal/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php, line 266

Class

ContainerBuilder
ContainerBuilder is a DI container that provides an API to easily describe services.

Namespace

Symfony\Component\DependencyInjection

Code

public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
  if ($this
    ->isFrozen()) {
    throw new BadMethodCallException('Setting service on a frozen container is not allowed');
  }
  $id = strtolower($id);
  unset($this->definitions[$id], $this->aliases[$id]);
  parent::set($id, $service, $scope);
}