public function Container::addScope

Adds a scope to the container.

@api

Parameters

ScopeInterface $scope:

Overrides ContainerInterface::addScope

File

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

Class

Container
Container is a dependency injection container.

Namespace

Symfony\Component\DependencyInjection

Code

public function addScope(ScopeInterface $scope) {
  $name = $scope
    ->getName();
  $parentScope = $scope
    ->getParentName();
  if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
    throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
  }
  if (isset($this->scopes[$name])) {
    throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
  }
  if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
    throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
  }
  $this->scopes[$name] = $parentScope;
  $this->scopeChildren[$name] = array();

  // normalize the child relations
  while ($parentScope !== self::SCOPE_CONTAINER) {
    $this->scopeChildren[$parentScope][] = $name;
    $parentScope = $this->scopes[$parentScope];
  }
}