also consider alias in Container::has()
This commit is contained in:
parent
8d29c64dcc
commit
aa79393054
@ -88,6 +88,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
|
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
|
||||||
|
|
||||||
$this->services = array();
|
$this->services = array();
|
||||||
|
$this->aliases = array();
|
||||||
$this->scopes = array();
|
$this->scopes = array();
|
||||||
$this->scopeChildren = array();
|
$this->scopeChildren = array();
|
||||||
$this->scopedServices = array();
|
$this->scopedServices = array();
|
||||||
@ -228,7 +229,10 @@ class Container implements IntrospectableContainerInterface
|
|||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$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')
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,6 +477,14 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return $reflection->getValue($obj);
|
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
|
class ProjectServiceContainer extends Container
|
||||||
@ -490,6 +498,7 @@ class ProjectServiceContainer extends Container
|
|||||||
$this->__bar = new \stdClass();
|
$this->__bar = new \stdClass();
|
||||||
$this->__foo_bar = new \stdClass();
|
$this->__foo_bar = new \stdClass();
|
||||||
$this->__foo_baz = new \stdClass();
|
$this->__foo_baz = new \stdClass();
|
||||||
|
$this->aliases = array('alias' => 'bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getScopedService()
|
protected function getScopedService()
|
||||||
|
Reference in New Issue
Block a user