Fix kernel.project_dir extensibility

This commit is contained in:
Robin Chalas 2017-05-17 11:20:42 +02:00
parent 98021ae918
commit 3230fc7e70
2 changed files with 42 additions and 2 deletions

View File

@ -82,7 +82,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface
$this->environment = $environment;
$this->debug = (bool) $debug;
$this->rootDir = $this->getRootDir();
$this->projectDir = $this->getProjectDir();
$this->name = $this->getName();
if ($this->debug) {
@ -604,7 +603,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
return array_merge(
array(
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
'kernel.project_dir' => realpath($this->projectDir) ?: $this->projectDir,
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug,
'kernel.name' => $this->name,

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
@ -761,6 +762,15 @@ EOF;
unset($_SERVER['SYMFONY__FOO__BAR']);
}
public function testProjectDirExtension()
{
$kernel = new CustomProjectDirKernel('test', true);
$kernel->boot();
$this->assertSame('foo', $kernel->getProjectDir());
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir'));
}
/**
* Returns a mock for the BundleInterface.
*
@ -857,3 +867,34 @@ class TestKernel implements HttpKernelInterface
{
}
}
class CustomProjectDirKernel extends Kernel
{
private $baseDir;
public function __construct()
{
parent::__construct('test', false);
$this->baseDir = 'foo';
}
public function registerBundles()
{
return array();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
public function getProjectDir()
{
return $this->baseDir;
}
public function getRootDir()
{
return __DIR__.'/Fixtures';
}
}