8000 Revert "bug #10979 Make rootPath part of regex greedy (artursvonda)" · symfony/symfony@af1c41c · GitHub
[go: up one dir, main page]

Skip to content

Commit af1c41c

Browse files
committed
Revert "bug #10979 Make rootPath part of regex greedy (artursvonda)"
This reverts commit 9766c72, reversing changes made to 168174a.
1 parent 8d29ca1 commit af1c41c

File tree

3 files changed

+12
-59
lines changed

3 files changed

+12
-59
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface
5353
protected $bundleMap;
5454
protected $container;
5555
protected $rootDir;
56-
protected $realRootDir;
5756
protected $environment;
5857
protected $debug;
5958
protected $booted;
@@ -732,17 +731,24 @@ private function removeAbsolutePathsFromContainer($content)
732731
return $content;
733732
}
734733

735-
$rootDir = $this->getRealRootDir();
736-
if (!$rootDir) {
737-
return $ 10000 content;
734+
// find the "real" root dir (by finding the composer.json file)
735+
$rootDir = $this->getRootDir();
736+
$previous = $rootDir;
737+
while (!file_exists($rootDir.'/composer.json')) {
738+
if ($previous === $rootDir = realpath($rootDir.'/..')) {
739+
// unable to detect the project root, give up
740+
return $content;
741+
}
742+
743+
$previous = $rootDir;
738744
}
739745

740746
$rootDir = rtrim($rootDir, '/');
741747
$cacheDir = $this->getCacheDir();
742748
$filesystem = new Filesystem();
743749

744-
return preg_replace_callback("{'([^']*?)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
745-
$prefix = !empty($match[1]) ? "'$match[1]'.__DIR__" : "__DIR__";
750+
return preg_replace_callback("{'([^']*)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
751+
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__";
746752

747753
if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) {
748754
return $prefix;
@@ -752,33 +758,6 @@ private function removeAbsolutePathsFromContainer($content)
752758
}, $content);
753759
}
754760

755-
/**
756-
* Find the "real" root dir (by finding the composer.json file)
757-
*
758-
* @return null|string
759-
*/
760-
private function getRealRootDir()
761-
{
762-
if (null !== $this->realRootDir) {
763-
return $this->realRootDir;
764-
}
765-
766-
$rootDir = $this->getRootDir();
767-
$previous = $rootDir;
768-
while (!file_exists($rootDir.'/composer.json')) {
769-
if ($previous === $rootDir = realpath($rootDir.'/..')) {
770-
// unable to detect the project root, give up
771-
return $this->realRootDir = false;
772-
}
773-
774-
$previous = $rootDir;
775-
}
776-
777-
$this->realRootDir = $rootDir;
778-
779-
return $this->realRootDir;
780-
}
781-
782761
/**
783762
* Returns a loader for the container.
784763
*

src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,4 @@ public function setIsBooted($value)
5656
{
5757
$this->booted = (bool) $value;
5858
}
59-
60-
public function setRealRootDir($dir)
61-
{
62-
$this->realRootDir = $dir;
63-
}
6459
}

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -852,27 +852,6 @@ public function testRemoveAbsolutePathsFromContainerGiveUpWhenComposerJsonPathNo
852852
$this->assertEquals($newContent, $content);
853853
}
854854

855-
public function testRemoveAbsolutePathsFromContainerWithSpecialCase()
856-
{
857-
$kernel = new KernelForTest('dev', true);
858-
$kernel->setRootDir('/app/app');
859-
$kernel->setRealRootDir('/app');
860-
$symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app';
861-
862-
$content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php');
863-
$content = str_replace('ROOT_DIR', '/app', $content);
864-
865-
$m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer');
866-
$m->setAccessible(true);
867-
$content = $m->invoke($kernel, $content);
868-
$this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content);
869-
}
870-
871-
/**
872-
* Returns a mock for the BundleInterface
873-
*
874-
* @return BundleInterface
875-
*/
876855
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)
877856
{
878857
$bundle = $this

0 commit comments

Comments
 (0)
0