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.
This commit is contained in:
commit
1ecfd447c1
@ -214,7 +214,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
|
|
||||||
$this->services[$id] = $service;
|
$this->services[$id] = $service;
|
||||||
|
|
||||||
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
|
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
|
||||||
$this->$method();
|
$this->$method();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
return isset($this->services[$id])
|
return isset($this->services[$id])
|
||||||
|| array_key_exists($id, $this->services)
|
|| array_key_exists($id, $this->services)
|
||||||
|| isset($this->aliases[$id])
|
|| isset($this->aliases[$id])
|
||||||
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
|
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
|
|
||||||
if (isset($this->methodMap[$id])) {
|
if (isset($this->methodMap[$id])) {
|
||||||
$method = $this->methodMap[$id];
|
$method = $this->methodMap[$id];
|
||||||
} elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
|
} elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
|
||||||
// $method is set to the right value, proceed
|
// $method is set to the right value, proceed
|
||||||
} else {
|
} else {
|
||||||
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
|
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
|
||||||
|
@ -188,6 +188,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
|
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
|
||||||
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
|
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
|
||||||
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
|
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
|
||||||
|
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
|
||||||
|
|
||||||
$sc->set('bar', $bar = new \stdClass());
|
$sc->set('bar', $bar = new \stdClass());
|
||||||
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
|
$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 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
|
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
|
||||||
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
|
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
|
||||||
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
|
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
|
||||||
|
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user