You are here

public function Container::addScope in Zircon Profile 8

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

Adds a scope to the container.

Parameters

ScopeInterface $scope:

Throws

InvalidArgumentException

Overrides ContainerInterface::addScope

File

vendor/symfony/dependency-injection/Container.php, line 468

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