[DependencyInjection] Fixed support for backslashes in service ids.
This change is for consistency with camelize() which is used in ProxyDumper and PhpDumper.
This commit is contained in:
parent
ba856e60bf
commit
c6f210b5ad
@ -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