This is called to leave the current scope, and move back to the parent scope.
@api
string $name The name of the scope to leave:
InvalidArgumentException if the scope is not active
Overrides ContainerInterface::leaveScope
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);
}
}
}
}