diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 8a2c1b3a1e..3c3ad425ce 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -471,7 +471,7 @@ class Container implements IntrospectableContainerInterface */ public static function camelize($id) { - return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id); + return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ '))), array(' ' => '')); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 23c13c5094..f762e7afec 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -30,6 +30,29 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument'); } + /** + * @dataProvider dataForTestCamelize + */ + public function testCamelize($id, $expected) + { + $this->assertEquals($expected, Container::camelize($id), sprintf('Container::camelize("%s")', $id)); + } + + public function dataForTestCamelize() + { + return array( + array('foo_bar', 'FooBar'), + array('foo.bar', 'Foo_Bar'), + array('foo.bar_baz', 'Foo_BarBaz'), + array('foo._bar', 'Foo_Bar'), + array('foo_.bar', 'Foo_Bar'), + array('_foo', 'Foo'), + array('.foo', '_Foo'), + array('foo_', 'Foo'), + array('foo.', 'Foo_'), + ); + } + /** * @covers Symfony\Component\DependencyInjection\Container::compile */