Merge branch '2.4' into 2.5
* 2.4: Revert "bug #10894 [HttpKernel] removed absolute paths from the generated container (fabpot)" Revert "bug #10937 [HttpKernel] Fix "absolute path" when we look to the cache directory (BenoitLeveque)" Revert "fixed CS" Revert "bug #10979 Make rootPath part of regex greedy (artursvonda)" Revert "[HttpKernel] simplified some tests" [HttpKernel] simplified some tests Make rootPath part of regex greedy
This commit is contained in:
commit
6cee250b55
@ -32,7 +32,6 @@ use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* The Kernel is the heart of the Symfony system.
|
||||
@ -715,47 +714,9 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$content = static::stripComments($content);
|
||||
}
|
||||
|
||||
$content = $this->removeAbsolutePathsFromContainer($content);
|
||||
|
||||
$cache->write($content, $container->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts absolute paths to relative ones in the dumped container.
|
||||
*/
|
||||
private function removeAbsolutePathsFromContainer($content)
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Filesystem\Filesystem')) {
|
||||
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 = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__";
|
||||
|
||||
if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) {
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
return $prefix.".'/".$relativePath."'";
|
||||
}, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a loader for the container.
|
||||
*
|
||||
|
@ -1,8 +0,0 @@
|
||||
'ROOT_DIR/app/cache/dev/foo'
|
||||
'ROOT_DIR/app/cache/foo'
|
||||
'ROOT_DIR/foo/bar.php'
|
||||
'ROOT_DIR/app/cache/dev'
|
||||
|
||||
'/some/where/else/foo'
|
||||
|
||||
'file:ROOT_DIR/app/cache/dev/profiler'
|
@ -1,8 +0,0 @@
|
||||
__DIR__.'/foo'
|
||||
__DIR__.'/../foo'
|
||||
__DIR__.'/../../../foo/bar.php'
|
||||
__DIR__
|
||||
|
||||
'/some/where/else/foo'
|
||||
|
||||
'file:'.__DIR__.'/profiler'
|
@ -1 +0,0 @@
|
||||
{}
|
@ -16,11 +16,6 @@ use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
|
||||
class KernelForTest extends Kernel
|
||||
{
|
||||
public function setRootDir($dir)
|
||||
{
|
||||
$this->rootDir = $dir;
|
||||
}
|
||||
|
||||
public function getBundleMap()
|
||||
{
|
||||
return $this->bundleMap;
|
||||
|
@ -722,34 +722,6 @@ EOF;
|
||||
$kernel->terminate(Request::create('/'), new Response());
|
||||
}
|
||||
|
||||
public function testRemoveAbsolutePathsFromContainer()
|
||||
{
|
||||
$kernel = new KernelForTest('dev', true);
|
||||
$kernel->setRootDir($symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app');
|
||||
|
||||
$content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php');
|
||||
$content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $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);
|
||||
}
|
||||
|
||||
public function testRemoveAbsolutePathsFromContainerGiveUpWhenComposerJsonPathNotGuessable()
|
||||
{
|
||||
$kernel = new KernelForTest('dev', true);
|
||||
$kernel->setRootDir($symfonyRootDir = sys_get_temp_dir());
|
||||
|
||||
$content = file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php');
|
||||
$content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content);
|
||||
|
||||
$m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer');
|
||||
$m->setAccessible(true);
|
||||
$newContent = $m->invoke($kernel, $content);
|
||||
$this->assertEquals($newContent, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mock for the BundleInterface
|
||||
*
|
||||
|
@ -29,7 +29,6 @@
|
||||
"symfony/console": "~2.2",
|
||||
"symfony/dependency-injection": "~2.0",
|
||||
"symfony/finder": "~2.0",
|
||||
"symfony/filesystem": "~2.4",
|
||||
"symfony/process": "~2.0",
|
||||
"symfony/routing": "~2.2",
|
||||
"symfony/stopwatch": "~2.2",
|
||||
@ -41,8 +40,7 @@
|
||||
"symfony/config": "",
|
||||
"symfony/console": "",
|
||||
"symfony/dependency-injection": "",
|
||||
"symfony/finder": "",
|
||||
"symfony/filesystem": ""
|
||||
"symfony/finder": ""
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Symfony\\Component\\HttpKernel\\": "" }
|
||||
|
Reference in New Issue
Block a user