8000 [DI] Resolve aliases earlier · symfony/symfony@9922827 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9922827

Browse files
[DI] Resolve aliases earlier
1 parent 559ccb2 commit 9922827

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,16 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
249249
// this method can be called thousands of times during a request, avoid
250250
// calling strtolower() unless necessary.
251251
for ($i = 2;;) {
252-
if ('service_container' === $id) {
253-
return $this;
254-
}
255252
if (isset($this->aliases[$id])) {
256253
$id = $this->aliases[$id];
257254
}
258255
// Re-use shared service instance if it exists.
259256
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
260257
return $this->services[$id];
261258
}
259+
if ('service_container' === $id) {
260+
return $this;
261+
}
262262

263263
if (isset($this->loading[$id])) {
264264
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
@@ -328,16 +328,16 @@ public function initialized($id)
328328
{
329329
$id = strtolower($id);
330330

331+
if (isset($this->aliases[$id])) {
332+
$id = $this->aliases[$id];
333+
}
334+
331335
if ('service_container' === $id) {
332336
// BC: 'service_container' was a synthetic service previously.
333337
// @todo Change to false in next major release.
334338
return true;
335339
}
336340

337-
if (isset($this->aliases[$id])) {
338-
$id = $this->aliases[$id];
339-
}
340-
341341
return isset($this->services[$id]) || array_key_exists($id, $this->services);
342342
}
343343

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,10 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
14821482
*/
14831483
private function getServiceCall($id, Reference $reference = null)
14841484
{
1485+
while ($this->container->hasAlias($id)) {
1486+
$id = (string) $this->container->getAlias($id);
1487+
}
1488+
14851489
if ('service_container' === $id) {
14861490
return '$this';
14871491
}
@@ -1490,10 +1494,6 @@ private function getServiceCall($id, Reference $reference = null)
14901494
return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
14911495
}
14921496

1493-
if ($this->container->hasAlias($id)) {
1494-
$id = (string) $this->container->getAlias($id);
1495-
}
1496-
14971497
return sprintf('$this->get(\'%s\')', $id);
14981498
}
14991499

0 commit comments

Comments
 (0)
0