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

Skip to content

Commit 1ecfd44

Browse files
committed
bug #9834 [DependencyInjection] Fixed support for backslashes in service ids. (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] Fixed support for backslashes in service ids. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9801 | License | MIT | Doc PR | This change is needed for consistency with `camelize()` which is used in [`ProxyDumper`](https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php#L69) and [`PhpDumper`](https://github.com/symfony/DependencyInjection/blob/2.3/Dumper/PhpDumper.php#L1275). Either this PR needs to be merged for consistency or #9610 rolled back (if we don't want to support backslashes in service ids). Anyone could tell me why we're not using the `camelize()` method internally in the `Container`? Commits ------- c6f210b [DependencyInjection] Fixed support for backslashes in service ids.
2 parents 0689cab + c6f210b commit 1ecfd44

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)