public function Container::leaveScope

This is called to leave the current scope, and move back to the parent scope.

@api

Parameters

string $name The name of the scope to leave:

Throws

InvalidArgumentException if the scope is not active

Overrides ContainerInterface::leaveScope

File

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

Class

Container
Container is a dependency injection container.

Namespace

Symfony\Component\DependencyInjection

Code

public function leaveScope($name) {
  if (!isset($this->scopedServices[$name])) {
    throw new InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
  }

  // remove all services of this scope, or any of its child scopes from
  // the global service map
  $services = array(
    $this->services,
    $this->scopedServices[$name],
  );
  unset($this->scopedServices[$name]);
  foreach ($this->scopeChildren[$name] as $child) {
    if (!isset($this->scopedServices[$child])) {
      continue;
    }
    $services[] = $this->scopedServices[$child];
    unset($this->scopedServices[$child]);
  }
  $this->services = call_user_func_array('array_diff_key', $services);

  // check if we need to restore services of a previous scope of this type
  if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
    $services = $this->scopeStacks[$name]
      ->pop();
    $this->scopedServices += $services;
    foreach ($services as $array) {
      foreach ($array as $id => $service) {
        $this
          ->set($id, $service, $name);
      }
    }
  }
}