diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 5eb34baab2..5362d05883 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -53,7 +53,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $bundleMap; protected $container; protected $rootDir; - protected $realRootDir; protected $environment; protected $debug; protected $booted; @@ -732,17 +731,24 @@ abstract class Kernel implements KernelInterface, TerminableInterface return $content; } - $rootDir = $this->getRealRootDir(); - if (!$rootDir) { - return $content; + // find the "real" root dir (by finding the composer.json file) + $rootDir = $this->getRootDir(); + $previous = $rootDir; + while (!file_exists($rootDir.'/composer.json')) { + if ($previous === $rootDir = realpath($rootDir.'/..')) { + // unable to detect the project root, give up + return $content; + } + + $previous = $rootDir; } $rootDir = rtrim($rootDir, '/'); $cacheDir = $this->getCacheDir(); $filesystem = new Filesystem(); - return preg_replace_callback("{'([^']*?)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) { - $prefix = !empty($match[1]) ? "'$match[1]'.__DIR__" : "__DIR__"; + return preg_replace_callback("{'([^']*)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) { + $prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__"; if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) { return $prefix; @@ -752,33 +758,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface }, $content); } - /** - * Find the "real" root dir (by finding the composer.json file) - * - * @return null|string - */ - private function getRealRootDir() - { - if (null !== $this->realRootDir) { - return $this->realRootDir; - } - - $rootDir = $this->getRootDir(); - $previous = $rootDir; - while (!file_exists($rootDir.'/composer.json')) { - if ($previous === $rootDir = realpath($rootDir.'/..')) { - // unable to detect the project root, give up - return $this->realRootDir = false; - } - - $previous = $rootDir; - } - - $this->realRootDir = $rootDir; - - return $this->realRootDir; - } - /** * Returns a loader for the container. * diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php index b012eb1bc3..3eb765d2b5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php @@ -56,9 +56,4 @@ class KernelForTest extends Kernel { $this->booted = (bool) $value; } - - public function setRealRootDir($dir) - { - $this->realRootDir = $dir; - } } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index d2a22c6ae4..95e8942d08 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -852,27 +852,6 @@ EOF; $this->assertEquals($newContent, $content); } - public function testRemoveAbsolutePathsFromContainerWithSpecialCase() - { - $kernel = new KernelForTest('dev', true); - $kernel->setRootDir('/app/app'); - $kernel->setRealRootDir('/app'); - $symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app'; - - $content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php'); - $content = str_replace('ROOT_DIR', '/app', $content); - - $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); - $m->setAccessible(true); - $content = $m->invoke($kernel, $content); - $this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content); - } - - /** - * Returns a mock for the BundleInterface - * - * @return BundleInterface - */ protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null) { $bundle = $this