[DI] Resolve aliases earlier
This commit is contained in:
parent
559ccb2c66
commit
9922827cc2
@ -249,9 +249,6 @@ class Container implements IntrospectableContainerInterface
|
|||||||
// this method can be called thousands of times during a request, avoid
|
// this method can be called thousands of times during a request, avoid
|
||||||
// calling strtolower() unless necessary.
|
// calling strtolower() unless necessary.
|
||||||
for ($i = 2;;) {
|
for ($i = 2;;) {
|
||||||
if ('service_container' === $id) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
if (isset($this->aliases[$id])) {
|
if (isset($this->aliases[$id])) {
|
||||||
$id = $this->aliases[$id];
|
$id = $this->aliases[$id];
|
||||||
}
|
}
|
||||||
@ -259,6 +256,9 @@ class Container implements IntrospectableContainerInterface
|
|||||||
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
|
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
|
||||||
return $this->services[$id];
|
return $this->services[$id];
|
||||||
}
|
}
|
||||||
|
if ('service_container' === $id) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($this->loading[$id])) {
|
if (isset($this->loading[$id])) {
|
||||||
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
|
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
|
||||||
@ -328,16 +328,16 @@ class Container implements IntrospectableContainerInterface
|
|||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
|
if (isset($this->aliases[$id])) {
|
||||||
|
$id = $this->aliases[$id];
|
||||||
|
}
|
||||||
|
|
||||||
if ('service_container' === $id) {
|
if ('service_container' === $id) {
|
||||||
// BC: 'service_container' was a synthetic service previously.
|
// BC: 'service_container' was a synthetic service previously.
|
||||||
// @todo Change to false in next major release.
|
// @todo Change to false in next major release.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->aliases[$id])) {
|
|
||||||
$id = $this->aliases[$id];
|
|
||||||
}
|
|
||||||
|
|
||||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1482,6 +1482,10 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
private function getServiceCall($id, Reference $reference = null)
|
private function getServiceCall($id, Reference $reference = null)
|
||||||
{
|
{
|
||||||
|
while ($this->container->hasAlias($id)) {
|
||||||
|
$id = (string) $this->container->getAlias($id);
|
||||||
|
}
|
||||||
|
|
||||||
if ('service_container' === $id) {
|
if ('service_container' === $id) {
|
||||||
return '$this';
|
return '$this';
|
||||||
}
|
}
|
||||||
@ -1490,10 +1494,6 @@ EOF;
|
|||||||
return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
|
return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->container->hasAlias($id)) {
|
|
||||||
$id = (string) $this->container->getAlias($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf('$this->get(\'%s\')', $id);
|
return sprintf('$this->get(\'%s\')', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user