[DependencyInjection] changed the order of priority when a service is both defined with setService() and with a getXXXService() method
This commit is contained in:
parent
dd759bd0b6
commit
2ac6faaa0b
@ -194,16 +194,16 @@ class Container implements ContainerInterface, \ArrayAccess, \Iterator
|
|||||||
throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true))));
|
throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->services[$id]))
|
|
||||||
{
|
|
||||||
return $this->services[$id];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
|
if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
|
||||||
{
|
{
|
||||||
return $this->$method();
|
return $this->$method();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->services[$id]))
|
||||||
|
{
|
||||||
|
return $this->services[$id];
|
||||||
|
}
|
||||||
|
|
||||||
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)
|
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)
|
||||||
{
|
{
|
||||||
throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $id));
|
throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $id));
|
||||||
|
@ -155,7 +155,7 @@ $t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($sc->__bar), '->
|
|||||||
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
|
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
|
||||||
|
|
||||||
$sc->setService('bar', $bar = new stdClass());
|
$sc->setService('bar', $bar = new stdClass());
|
||||||
$t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with setService() than one defined with a getXXXService() method');
|
$t->isnt(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with a getXXXService() method than one defined with setService()');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user