From 31da8394473a563f92bc41bdf71b67de9027925b Mon Sep 17 00:00:00 2001 From: Arturs Vonda Date: Fri, 23 May 2014 17:32:35 +0300 Subject: [PATCH 1/7] Make rootPath part of regex greedy - Fixes #10977 --- src/Symfony/Component/HttpKernel/Kernel.php | 45 ++++++++++++++----- .../Tests/Fixtures/KernelForTest.php | 5 +++ .../Component/HttpKernel/Tests/KernelTest.php | 21 +++++++++ 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 5362d05883..5eb34baab2 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -53,6 +53,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $bundleMap; protected $container; protected $rootDir; + protected $realRootDir; protected $environment; protected $debug; protected $booted; @@ -731,24 +732,17 @@ abstract class Kernel implements KernelInterface, TerminableInterface 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 = $this->getRealRootDir(); + if (!$rootDir) { + return $content; } $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__"; + return preg_replace_callback("{'([^']*?)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) { + $prefix = !empty($match[1]) ? "'$match[1]'.__DIR__" : "__DIR__"; if ('.' === $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')) { return $prefix; @@ -758,6 +752,33 @@ 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 3eb765d2b5..b012eb1bc3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php @@ -56,4 +56,9 @@ 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 95e8942d08..d2a22c6ae4 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -852,6 +852,27 @@ 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 From ccacd8d2af428de1cf3df3e25757d4e4a20ab5e1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:12:56 +0200 Subject: [PATCH 2/7] [HttpKernel] simplified some tests --- .../Component/HttpKernel/Tests/KernelTest.php | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index d2a22c6ae4..82a7561377 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -824,48 +824,37 @@ EOF; $kernel->terminate(Request::create('/'), new Response()); } - public function testRemoveAbsolutePathsFromContainer() + /** + * @dataProvider getRemoveAbsolutePathsFromContainerData + */ + public function testRemoveAbsolutePathsFromContainer($symfonyRootDir, $realRootDir, $replacement, $replaced) { $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()); + $kernel->setRootDir($symfonyRootDir); + if (null !== $realRootDir) { + $kernel->setRealRootDir($realRootDir); + } $content = file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php'); - $content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content); + $content = str_replace('ROOT_DIR', $replacement, $content); $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); $m->setAccessible(true); $newContent = $m->invoke($kernel, $content); - $this->assertEquals($newContent, $content); + if ($replaced) { + $this->assertEquals(file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php'), $newContent); + } else { + $this->assertEquals($newContent, $content); + } } - public function testRemoveAbsolutePathsFromContainerWithSpecialCase() + public function getRemoveAbsolutePathsFromContainerData() { - $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); + return array( + array(__DIR__.'/Fixtures/DumpedContainers/app', null, __DIR__.'/Fixtures/DumpedContainers', true), + array(sys_get_temp_dir(), null, __DIR__.'/Fixtures/DumpedContainers', false), + array('/app/app', '/app', '/app', true), + ); } /** From 8d29ca160d02b1e3cee6f87fa55e61505b054e24 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:41:51 +0200 Subject: [PATCH 3/7] Revert "[HttpKernel] simplified some tests" This reverts commit ccacd8d2af428de1cf3df3e25757d4e4a20ab5e1. --- .../Component/HttpKernel/Tests/KernelTest.php | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 82a7561377..d2a22c6ae4 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -824,37 +824,48 @@ EOF; $kernel->terminate(Request::create('/'), new Response()); } - /** - * @dataProvider getRemoveAbsolutePathsFromContainerData - */ - public function testRemoveAbsolutePathsFromContainer($symfonyRootDir, $realRootDir, $replacement, $replaced) + public function testRemoveAbsolutePathsFromContainer() { $kernel = new KernelForTest('dev', true); - $kernel->setRootDir($symfonyRootDir); - if (null !== $realRootDir) { - $kernel->setRealRootDir($realRootDir); - } + $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', $replacement, $content); + $content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content); $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); $m->setAccessible(true); $newContent = $m->invoke($kernel, $content); - if ($replaced) { - $this->assertEquals(file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php'), $newContent); - } else { - $this->assertEquals($newContent, $content); - } + $this->assertEquals($newContent, $content); } - public function getRemoveAbsolutePathsFromContainerData() + public function testRemoveAbsolutePathsFromContainerWithSpecialCase() { - return array( - array(__DIR__.'/Fixtures/DumpedContainers/app', null, __DIR__.'/Fixtures/DumpedContainers', true), - array(sys_get_temp_dir(), null, __DIR__.'/Fixtures/DumpedContainers', false), - array('/app/app', '/app', '/app', true), - ); + $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); } /** From af1c41c2fc9d2d73a0452e5710a405d8acd94527 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:41:54 +0200 Subject: [PATCH 4/7] Revert "bug #10979 Make rootPath part of regex greedy (artursvonda)" This reverts commit 9766c72324e3a073bc76eeafd754479a7dd01d8b, reversing changes made to 168174af08f213f6797fde47a570356c0e4919e0. --- src/Symfony/Component/HttpKernel/Kernel.php | 45 +++++-------------- .../Tests/Fixtures/KernelForTest.php | 5 --- .../Component/HttpKernel/Tests/KernelTest.php | 21 --------- 3 files changed, 12 insertions(+), 59 deletions(-) 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 From d1f77c6d0d368531ba8a254e9572a1672cc02db1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:41:58 +0200 Subject: [PATCH 5/7] Revert "fixed CS" This reverts commit 11816c5e518bf6e1aa25f457bd861394a6e4bf1d. --- src/Symfony/Component/HttpKernel/Kernel.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 5362d05883..9067c8ccef 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -750,11 +750,13 @@ abstract class Kernel implements KernelInterface, TerminableInterface 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), '/')) { + $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/'); + + if ($relativePath === '.') { return $prefix; } - return $prefix.".'/".$relativePath."'"; + return $prefix . ".'/" . $relativePath . "'"; }, $content); } From 55888299be3a4f8155de37e5ada1000119a4d88f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:42:01 +0200 Subject: [PATCH 6/7] Revert "bug #10937 [HttpKernel] Fix "absolute path" when we look to the cache directory (BenoitLeveque)" This reverts commit 7dc8931969cdf55820c40757a1da9906b9fb013d, reversing changes made to 309046a2072efe83d2f3cf7da87d6b76d33429a4. --- src/Symfony/Component/HttpKernel/Kernel.php | 10 ++-------- .../app/cache/dev/withAbsolutePaths.php | 1 - .../app/cache/dev/withoutAbsolutePaths.php | 1 - 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 9067c8ccef..002c34b99d 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -748,15 +748,9 @@ abstract class Kernel implements KernelInterface, TerminableInterface $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__"; + $prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__.'/" : "__DIR__.'/"; - $relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/'); - - if ($relativePath === '.') { - return $prefix; - } - - return $prefix . ".'/" . $relativePath . "'"; + return $prefix.rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')."'"; }, $content); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php index b8644ecb9f..54e0dedc4b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php @@ -1,7 +1,6 @@ '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' diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php index 36823dfc16..09ce8b5683 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php @@ -1,7 +1,6 @@ __DIR__.'/foo' __DIR__.'/../foo' __DIR__.'/../../../foo/bar.php' -__DIR__ '/some/where/else/foo' From 5d13be7c71ed3df9ce50cd2f6a7309802e60a577 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:42:04 +0200 Subject: [PATCH 7/7] Revert "bug #10894 [HttpKernel] removed absolute paths from the generated container (fabpot)" This reverts commit 735e9a4768962b6d5098733c347cff0df6b9cd36, reversing changes made to 5c91dc1a3a49c6d5fdc05fea3962355badf8e9fd. --- src/Symfony/Component/HttpKernel/Kernel.php | 35 ------------------- .../app/cache/dev/withAbsolutePaths.php | 7 ---- .../app/cache/dev/withoutAbsolutePaths.php | 7 ---- .../Fixtures/DumpedContainers/composer.json | 1 - .../Tests/Fixtures/KernelForTest.php | 5 --- .../Component/HttpKernel/Tests/KernelTest.php | 28 --------------- .../Component/HttpKernel/composer.json | 4 +-- 7 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php delete mode 100644 src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php delete mode 100644 src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/composer.json diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 002c34b99d..4ba29fcbfa 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -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. @@ -717,43 +716,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__.'/"; - - return $prefix.rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')."'"; - }, $content); - } - /** * Returns a loader for the container. * diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php deleted file mode 100644 index 54e0dedc4b..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php +++ /dev/null @@ -1,7 +0,0 @@ -'ROOT_DIR/app/cache/dev/foo' -'ROOT_DIR/app/cache/foo' -'ROOT_DIR/foo/bar.php' - -'/some/where/else/foo' - -'file:ROOT_DIR/app/cache/dev/profiler' diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php deleted file mode 100644 index 09ce8b5683..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php +++ /dev/null @@ -1,7 +0,0 @@ -__DIR__.'/foo' -__DIR__.'/../foo' -__DIR__.'/../../../foo/bar.php' - -'/some/where/else/foo' - -'file:'.__DIR__.'/profiler' diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/composer.json b/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/composer.json deleted file mode 100644 index 0967ef424b..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/composer.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php index 3eb765d2b5..21583ad40a 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php @@ -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; diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 95e8942d08..a19bc32679 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -824,34 +824,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); - } - protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null) { $bundle = $this diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 9b52591d9f..af659da904 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -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\\": "" }