Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Foundation] normalized app name for use in a class name
  • Loading branch information
fabpot committed Jun 1, 2010
1 parent 59f60ab commit 1a3790a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Symfony/Foundation/Kernel.php
Expand Up @@ -217,6 +217,11 @@ public function getName()
return $this->name;
}

public function getSafeName()
{
return preg_replace('/[^a-zA-Z0-9_]+/', '', $this->name);
}

public function getEnvironment()
{
return $this->environment;
Expand Down Expand Up @@ -254,7 +259,7 @@ public function getLogDir()

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;

Expand Down
54 changes: 54 additions & 0 deletions tests/Symfony/Tests/Foundation/KernelTest.php
@@ -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()
{
}
}

0 comments on commit 1a3790a

Please sign in to comment.