8000 [DependencyInjection] changed the order of priority when a service is… · Dahipster/symfony@2ac6faa · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ac6faa

Browse files
committed
[DependencyInjection] changed the order of priority when a service is both defined with setService() and with a getXXXService() method
1 parent dd759bd commit 2ac6faa

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Symfony/Components/DependencyInjection/Container.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ public function getService($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_RE
194194
throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true))));
195195
}
196196

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

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

207207
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)

tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected function getFoo_BazService()
155155
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
156156

157157
$sc->setService('bar', $bar = new stdClass());
158-
$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');
158+
$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()');
159159

160160
try
161161
{

0 commit comments

Comments
 (0)
0