Skip to content

Commit f244eb8

Browse files
committed
[HttpKernel] fixed Kernel name when stored in a directory starting with a number
1 parent 4816f65 commit f244eb8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

+3
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ public function getName()
302302
{
303303
if (null === $this->name) {
304304
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
305+
if (ctype_digit($this->name[0])) {
306+
$this->name = '_'.$this->name;
307+
}
305308
}
306309

307310
return $this->name;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Fixtures\_123;
13+
14+
use Symfony\Component\HttpKernel\Kernel;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
17+
class Kernel123 extends Kernel
18+
{
19+
public function registerBundles()
20+
{
21+
return array();
22+
}
23+
24+
public function registerContainerConfiguration(LoaderInterface $loader)
25+
{
26+
}
27+
28+
public function getCacheDir()
29+
{
30+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/cache/'.$this->environment;
31+
}
32+
33+
public function getLogDir()
34+
{
35+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/logs';
36+
}
37+
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,14 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
762762
$kernel->terminate(Request::create('/'), new Response());
763763
}
764764

765+
public function testKernelRootDirNameStartingWithANumber()
766+
{
767+
$dir = __DIR__.'/Fixtures/123';
768+
require_once $dir.'/Kernel123.php';
769+
$kernel = new \Symfony\Component\HttpKernel\Tests\Fixtures\_123\Kernel123('dev', true);
770+
$this->assertEquals('_123', $kernel->getName());
771+
}
772+
765773
/**
766774
* Returns a mock for the BundleInterface.
767775
*

0 commit comments

Comments
 (0)