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

Skip to content

Commit f9c5705

Browse files
committed
Fix kernel.project_dir extensibility
1 parent 1bbc35a commit f9c5705

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
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;
17+
use Symfony\Component\Filesystem\Filesystem;
1618
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1719
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
1820
use Symfony\Component\HttpKernel\Kernel;
@@ -761,6 +763,15 @@ public function testSymfonyEnvironmentVariables()
761763
unset($_SERVER['SYMFONY__FOO__BAR']);
762764
}
763765

766+
public function testProjectDirExtension()
767+
{
768+
$kernel = new CustomProjectDirKernel('test', true);
769+
$kernel->boot();
770+
771+
$this->assertSame('foo', $kernel->getProjectDir());
772+
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir'));
773+
}
774+
764775
/**
765776
* Returns a mock for the BundleInterface.
766777
*
@@ -857,3 +868,37 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
857868
{
858869
}
859870
}
871+
872+
class CustomProjectDirKernel extends Kernel
873+
{
874+
private $baseDir;
875+
876+
public function __construct()
877+
{
878+
parent::__construct('test', false);
879+
880+
$this->baseDir = 'foo';
881+
}
882+
883+
884+
public function registerBundles()
885+
{
886+
return array();
887+
}
888+
889+
public function registerContainerConfiguration(LoaderInterface $loader)
890+
{
891+
}
892+
893+
public function getProjectDir()
894+
{
895+
return $this->baseDir;
896+
}
897+
898+
public function __destruct()
899+
{
900+
$fs = new Filesystem();
901+
$fs->remove($this->getCacheDir());
902+
$fs->remove($this->getLogDir());
903+
}
904+
}

0 commit comments

Comments
 (0)