[Foundation] normalized app name for use in a class name

This commit is contained in:
Fabien Potencier 2010-06-01 10:03:50 +02:00
parent 59f60abbd5
commit 1a3790a636
2 changed files with 60 additions and 1 deletions

View File

@ -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;

View File

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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()
{
}
}