Skip to content

Commit

Permalink
[DependencyInjection] changed the order of priority when a service is…
Browse files Browse the repository at this point in the history
… both defined with setService() and with a getXXXService() method
  • Loading branch information
fabpot committed Jan 22, 2010
1 parent dd759bd commit 2ac6faa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Components/DependencyInjection/Container.php
Expand Up @@ -194,14 +194,14 @@ public function getService($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_RE
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]))
if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
{
return $this->services[$id];
return $this->$method();
}

if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
if (isset($this->services[$id]))
{
return $this->$method();
return $this->services[$id];
}

if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)
Expand Down
Expand Up @@ -155,7 +155,7 @@ protected function getFoo_BazService()
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');

$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
{
Expand Down

0 comments on commit 2ac6faa

Please sign in to comment.