also consider alias in Container::has()

This commit is contained in:
Lukas Kahwe Smith 2013-06-12 12:05:49 +02:00
parent 8d29c64dcc
commit aa79393054
2 changed files with 14 additions and 1 deletions

View File

@ -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')
;
}
/**

View File

@ -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()