public function Container::enterScope

This is called when you enter a scope

@api

Parameters

string $name:

Overrides ContainerInterface::enterScope

File

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

Class

Container
Container is a dependency injection container.

Namespace

Symfony\Component\DependencyInjection

Code

public function enterScope($name) {
  if (!isset($this->scopes[$name])) {
    throw new InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
  }
  if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
    throw new RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
  }

  // check if a scope of this name is already active, if so we need to
  // remove all services of this scope, and those of any of its child
  // scopes from the global services map
  if (isset($this->scopedServices[$name])) {
    $services = array(
      $this->services,
      $name => $this->scopedServices[$name],
    );
    unset($this->scopedServices[$name]);
    foreach ($this->scopeChildren[$name] as $child) {
      $services[$child] = $this->scopedServices[$child];
      unset($this->scopedServices[$child]);
    }

    // update global map
    $this->services = call_user_func_array('array_diff_key', $services);
    array_shift($services);

    // add stack entry for this scope so we can restore the removed services later
    if (!isset($this->scopeStacks[$name])) {
      $this->scopeStacks[$name] = new \SplStack();
    }
    $this->scopeStacks[$name]
      ->push($services);
  }
  $this->scopedServices[$name] = array();
}