Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3230fc7

Browse files
committed
Fix kernel.project_dir extensibility
1 parent 98021ae commit 3230fc7

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function __construct($environment, $debug)
8282
$this->environment = $environment;
8383
$this->debug = (bool) $debug;
8484
$this->rootDir = $this->getRootDir();
85-
$this->projectDir = $this->getProjectDir();
8685
$this->name = $this->getName();
8786

8887
if ($this->debug) {
@@ -604,7 +603,7 @@ protected function getKernelParameters()
604603
return array_merge(
605604
array(
606605
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
607-
'kernel.project_dir' => realpath($this->projectDir) ?: $this->projectDir,
606+
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
608607
'kernel.environment' => $this->environment,
609608
'kernel.debug' => $this->debug,
610609
'kernel.name' => $this->name,

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1718
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
@@ -761,6 +762,15 @@ public function testSymfonyEnvironmentVariables()
761762
unset($_SERVER['SYMFONY__FOO__BAR']);
762763
}
763764

765+
public function testProjectDirExtension()
766+
{
767+
$kernel = new CustomProjectDirKernel('test', true);
768+
$kernel->boot();
769+
770+
$this->assertSame('foo', $kernel->getProjectDir());
771+
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir'));
772+
}
773+
764774
/**
765775
* Returns a mock for the BundleInterface.
766776
*
@@ -857,3 +867,34 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
857867
{
858868
}
859869
}
870+
871+
class CustomProjectDirKernel extends Kernel
872+
{
873+
private $baseDir;
874+
875+
public function __construct()
876+
{
877+
parent::__construct('test', false);
878+
879+
$this->baseDir = 'foo';
880+
}
881+
882+
public function registerBundles()
883+
{
884+
return array();
885+
}
886+
887+
public function registerContainerConfiguration(LoaderInterface $loader)
888+
{
889+
}
890+
891+
public function getProjectDir()
892+
{
893+
return $this->baseDir;
894+
}
895+
896+
public function getRootDir()
897+
{
898+
return __DIR__.'/Fixtures';
899+
}
900+
}

0 commit comments

Comments
 (0)