Revert "bug #10979 Make rootPath part of regex greedy (artursvonda)"

This reverts commit 9766c72324, reversing
changes made to 168174af08.
This commit is contained in:
Fabien Potencier 2014-05-26 18:41:54 +02:00
parent 8d29ca160d
commit af1c41c2fc
3 changed files with 12 additions and 59 deletions

View File

@ -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.
*

View File

@ -56,9 +56,4 @@ class KernelForTest extends Kernel
{
$this->booted = (bool) $value;
}
public function setRealRootDir($dir)
{
$this->realRootDir = $dir;
}
}

View File

@ -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