parent
168174af08
commit
31da839447
@ -53,6 +53,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
protected $bundleMap;
|
protected $bundleMap;
|
||||||
protected $container;
|
protected $container;
|
||||||
protected $rootDir;
|
protected $rootDir;
|
||||||
|
protected $realRootDir;
|
||||||
protected $environment;
|
protected $environment;
|
||||||
protected $debug;
|
protected $debug;
|
||||||
protected $booted;
|
protected $booted;
|
||||||
@ -731,24 +732,17 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the "real" root dir (by finding the composer.json file)
|
$rootDir = $this->getRealRootDir();
|
||||||
$rootDir = $this->getRootDir();
|
if (!$rootDir) {
|
||||||
$previous = $rootDir;
|
|
||||||
while (!file_exists($rootDir.'/composer.json')) {
|
|
||||||
if ($previous === $rootDir = realpath($rootDir.'/..')) {
|
|
||||||
// unable to detect the project root, give up
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
$previous = $rootDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rootDir = rtrim($rootDir, '/');
|
$rootDir = rtrim($rootDir, '/');
|
||||||
$cacheDir = $this->getCacheDir();
|
$cacheDir = $this->getCacheDir();
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
|
|
||||||
return preg_replace_callback("{'([^']*)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
|
return preg_replace_callback("{'([^']*?)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
|
||||||
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__";
|
$prefix = !empty($match[1]) ? "'$match[1]'.__DIR__" : "__DIR__";
|
||||||
|
|
||||||
if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) {
|
if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) {
|
||||||
return $prefix;
|
return $prefix;
|
||||||
@ -758,6 +752,33 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
}, $content);
|
}, $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.
|
* Returns a loader for the container.
|
||||||
*
|
*
|
||||||
|
@ -56,4 +56,9 @@ class KernelForTest extends Kernel
|
|||||||
{
|
{
|
||||||
$this->booted = (bool) $value;
|
$this->booted = (bool) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRealRootDir($dir)
|
||||||
|
{
|
||||||
|
$this->realRootDir = $dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,6 +852,27 @@ EOF;
|
|||||||
$this->assertEquals($newContent, $content);
|
$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)
|
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)
|
||||||
{
|
{
|
||||||
$bundle = $this
|
$bundle = $this
|
||||||
|
Reference in New Issue
Block a user