Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6f210b

Browse files
committed
[DependencyInjection] Fixed support for backslashes in service ids.
This change is for consistency with camelize() which is used in ProxyDumper and PhpDumper.
1 parent ba856e6 commit c6f210b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
214214

215215
$this->services[$id] = $service;
216216

217-
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
217+
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
218218
$this->$method();
219219
}
220220

@@ -243,7 +243,7 @@ public function has($id)
243243
return isset($this->services[$id])
244244
|| array_key_exists($id, $this->services)
245245
|| isset($this->aliases[$id])
246-
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
246+
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')
247247
;
248248
}
249249

@@ -291,7 +291,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
291291

292292
if (isset($this->methodMap[$id])) {
293293
$method = $this->methodMap[$id];
294-
} elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
294+
} elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
295295
// $method is set to the right value, proceed
296296
} else {
297297
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function testGet()
188188
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
189189
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
190190
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
191+
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
191192

192193
$sc->set('bar', $bar = new \stdClass());
193194
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
@@ -259,6 +260,7 @@ public function testHas()
259260
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
260261
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
261262
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
263+
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
262264
}
263265

264266
/**

0 commit comments

Comments
 (0)