8000 merged branch lsmith77/container_check_alias_in_has_method (PR #8252) · symfony/symfony@6d2bec7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d2bec7

Browse files
committed
merged branch lsmith77/container_check_alias_in_has_method (PR #8252)
This PR was merged into the 2.3 branch. Discussion ---------- Container check alias in has method | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | [![Build Status](https://travis-ci.org/lsmith77/symfony.png?branch=container_check_alias_in_has_method)](https://travis-ci.org/lsmith77/symfony) | Fixed tickets | - | License | MIT | Doc PR | - This bug might also be in 2.2 but we encountered it in 2.3 and the relevant code was changed slightly from 2.2 to 2.3. We noticed this issue here: symfony-cmf/routing-bundle#109 The issue is caused by the ``$container->has->('router')`` check in the Router related commands: https://github.com/symfony/FrameworkBundle/blob/master/Command/RouterDebugCommand.php#L32 As with the CMF we use a chain router service that is aliased to ``router``, the commands do not get registered. One could classify this as a BC break, but imho its a bug fix. Commits ------- aa79393 also consider alias in Container::has()
2 parents d849d5d + aa79393 commit 6d2bec7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function __construct(ParameterBagInterface $parameterBag = null)
8888
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
8989

9090
$this->services = array();
91+
$this->aliases = array();
9192
$this->scopes = array();
9293
$this->scopeChildren = array();
9394
$this->scopedServices = array();
@@ -228,7 +229,10 @@ public function has($id)
228229
{
229230
$id = strtolower($id);
230231

231-
return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
232+
return array_key_exists($id, $this->services)
233+
|| array_key_exists($id, $this->aliases)
234+
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
235+
;
232236
}
233237

234238
/**

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ protected function getField($obj, $field)
477477

478478
return $reflection->getValue($obj);
479479
}
480+
481+
public function testAlias()
482+
{
483+
$c = new ProjectServiceContainer();
484+
485+
$this->assertTrue($c->has('alias'));
486+
$this->assertSame($c->get('alias'), $c->get('bar'));
487+
}
480488
}
481489

482490
class ProjectServiceContainer extends Container
@@ -490,6 +498,7 @@ public function __construct()
490498
$this->__bar = new \stdClass();
491499
$this->__foo_bar = new \stdClass();
492500
$this->__foo_baz = new \stdClass();
501+
$this->aliases = array('alias' => 'bar');
493502
}
494503

495504
protected function getScopedService()

0 commit comments

Comments
 (0)
0