diff --git a/src/Symfony/Foundation/Kernel.php b/src/Symfony/Foundation/Kernel.php index 9517cba9d4..5065575b58 100644 --- a/src/Symfony/Foundation/Kernel.php +++ b/src/Symfony/Foundation/Kernel.php @@ -217,6 +217,11 @@ abstract class Kernel implements HttpKernelInterface, \Serializable return $this->name; } + public function getSafeName() + { + return preg_replace('/[^a-zA-Z0-9_]+/', '', $this->name); + } + public function getEnvironment() { return $this->environment; @@ -254,7 +259,7 @@ abstract class Kernel implements HttpKernelInterface, \Serializable protected function initializeContainer() { - $class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; + $class = $this->getSafeName().ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; $location = $this->getCacheDir().'/'.$class; $reload = $this->debug ? $this->needsReload($class, $location) : false; diff --git a/tests/Symfony/Tests/Foundation/KernelTest.php b/tests/Symfony/Tests/Foundation/KernelTest.php new file mode 100644 index 0000000000..8a77f09e6c --- /dev/null +++ b/tests/Symfony/Tests/Foundation/KernelTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Foundation; + +use Symfony\Foundation\Kernel; + +class KernelTest extends \PHPUnit_Framework_TestCase +{ + public function testGetSafeName() + { + $kernel = new KernelForTest('dev', true, '-foo-'); + + $this->assertEquals('foo', $kernel->getSafeName()); + } +} + +class KernelForTest extends Kernel +{ + public function __construct($environment, $debug, $name) + { + parent::__construct($environment, $debug); + + $this->name = $name; + } + + public function registerRootDir() + { + } + + public function registerBundles() + { + } + + public function registerBundleDirs() + { + } + + public function registerContainerConfiguration() + { + } + + public function registerRoutes() + { + } +} \ No newline at end of file