You are here

public function ContainerBuilder::set in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/dependency-injection/ContainerBuilder.php \Symfony\Component\DependencyInjection\ContainerBuilder::set()
  2. 8 core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder::set()
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder::set()

Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().

Drupal's container builder can be used at runtime after compilation, so we override Symfony's ContainerBuilder's restriction on setting services in a frozen builder.

@todo Restrict this to synthetic services only. Ideally, the upstream ContainerBuilder class should be fixed to allow setting synthetic services in a frozen builder.

Overrides ContainerBuilder::set

File

core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php, line 43
Contains \Drupal\Core\DependencyInjection\ContainerBuilder.

Class

ContainerBuilder
Drupal's dependency injection container builder.

Namespace

Drupal\Core\DependencyInjection

Code

public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
  if (strtolower($id) !== $id) {
    throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
  }
  SymfonyContainer::set($id, $service, $scope);

  // Ensure that the _serviceId property is set on synthetic services as well.
  if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
    $this->services[$id]->_serviceId = $id;
  }
}