Skip to content

Commit

Permalink
bug #21883 [HttpKernel] fix Kernel name when stored in a directory st…
Browse files Browse the repository at this point in the history
…arting with a number (fabpot)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpKernel] fix Kernel name when stored in a directory starting with a number

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20489
| License       | MIT
| Doc PR        | -

replaces #20750

Commits
-------

f244eb8 [HttpKernel] fixed Kernel name when stored in a directory starting with a number
  • Loading branch information
fabpot committed Mar 6, 2017
2 parents 24f3135 + f244eb8 commit ec134c7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -302,6 +302,9 @@ public function getName()
{
if (null === $this->name) {
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
if (ctype_digit($this->name[0])) {
$this->name = '_'.$this->name;
}
}

return $this->name;
Expand Down
37 changes: 37 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/Fixtures/123/Kernel123.php
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests\Fixtures\_123;

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class Kernel123 extends Kernel
{
public function registerBundles()
{
return array();
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
}

public function getCacheDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/cache/'.$this->environment;
}

public function getLogDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/logs';
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -762,6 +762,14 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
$kernel->terminate(Request::create('/'), new Response());
}

public function testKernelRootDirNameStartingWithANumber()
{
$dir = __DIR__.'/Fixtures/123';
require_once $dir.'/Kernel123.php';
$kernel = new \Symfony\Component\HttpKernel\Tests\Fixtures\_123\Kernel123('dev', true);
$this->assertEquals('_123', $kernel->getName());
}

/**
* Returns a mock for the BundleInterface.
*
Expand Down

0 comments on commit ec134c7

Please sign in to comment.