Fixed self-reference in 'service_container' service breaks garbage collection (and clone).

This commit is contained in:
sun 2014-07-19 20:07:52 +02:00 committed by Fabien Potencier
parent 497c875304
commit 440322effc

View File

@ -93,8 +93,6 @@ class Container implements IntrospectableContainerInterface
$this->scopeChildren = array(); $this->scopeChildren = array();
$this->scopedServices = array(); $this->scopedServices = array();
$this->scopeStacks = array(); $this->scopeStacks = array();
$this->set('service_container', $this);
} }
/** /**
@ -204,6 +202,12 @@ class Container implements IntrospectableContainerInterface
$id = strtolower($id); $id = strtolower($id);
if ('service_container' === $id) {
// BC: 'service_container' is no longer a self-reference but always
// $this, so ignore this call.
// @todo Throw InvalidArgumentException in next major release.
return;
}
if (self::SCOPE_CONTAINER !== $scope) { if (self::SCOPE_CONTAINER !== $scope) {
if (!isset($this->scopedServices[$scope])) { if (!isset($this->scopedServices[$scope])) {
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id)); throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
@ -240,6 +244,10 @@ class Container implements IntrospectableContainerInterface
{ {
$id = strtolower($id); $id = strtolower($id);
if ('service_container' === $id) {
return true;
}
return isset($this->services[$id]) return isset($this->services[$id])
|| array_key_exists($id, $this->services) || array_key_exists($id, $this->services)
|| isset($this->aliases[$id]) || isset($this->aliases[$id])
@ -276,6 +284,9 @@ class Container implements IntrospectableContainerInterface
if ($strtolower) { if ($strtolower) {
$id = strtolower($id); $id = strtolower($id);
} }
if ('service_container' === $id) {
return $this;
}
if (isset($this->aliases[$id])) { if (isset($this->aliases[$id])) {
$id = $this->aliases[$id]; $id = $this->aliases[$id];
} }
@ -347,6 +358,12 @@ class Container implements IntrospectableContainerInterface
{ {
$id = strtolower($id); $id = strtolower($id);
if ('service_container' === $id) {
// BC: 'service_container' was a synthetic service previously.
// @todo Change to false in next major release.
return true;
}
return isset($this->services[$id]) || array_key_exists($id, $this->services); return isset($this->services[$id]) || array_key_exists($id, $this->services);
} }
@ -364,6 +381,7 @@ class Container implements IntrospectableContainerInterface
$ids[] = self::underscore($match[1]); $ids[] = self::underscore($match[1]);
} }
} }
$ids[] = 'service_container';
return array_unique(array_merge($ids, array_keys($this->services))); return array_unique(array_merge($ids, array_keys($this->services)));
} }