diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index ef561e1ded..b97f8a2c03 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -88,6 +88,7 @@ class Container implements IntrospectableContainerInterface $this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag; $this->services = array(); + $this->aliases = array(); $this->scopes = array(); $this->scopeChildren = array(); $this->scopedServices = array(); @@ -228,7 +229,10 @@ class Container implements IntrospectableContainerInterface { $id = strtolower($id); - return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service'); + return array_key_exists($id, $this->services) + || array_key_exists($id, $this->aliases) + || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') + ; } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index f49a567f52..c87f2c2b9a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -477,6 +477,14 @@ class ContainerTest extends \PHPUnit_Framework_TestCase return $reflection->getValue($obj); } + + public function testAlias() + { + $c = new ProjectServiceContainer(); + + $this->assertTrue($c->has('alias')); + $this->assertSame($c->get('alias'), $c->get('bar')); + } } class ProjectServiceContainer extends Container @@ -490,6 +498,7 @@ class ProjectServiceContainer extends Container $this->__bar = new \stdClass(); $this->__foo_bar = new \stdClass(); $this->__foo_baz = new \stdClass(); + $this->aliases = array('alias' => 'bar'); } protected function getScopedService()