Skip to content

Commit 7dc8931

Browse files
committed
bug symfony#10937 [HttpKernel] Fix "absolute path" when we look to the cache directory (BenoitLeveque)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes symfony#10937). Discussion ---------- [HttpKernel] Fix "absolute path" when we look to the cache directory | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | We should get ``__DIR__`` instead of ``__DIR__ . '/.'`` I've seen this issue when trying to play with the symfony standard new directory structure Commits ------- 4735e56 Fix "absolute path" when we look to the cache directory
2 parents 309046a + 4735e56 commit 7dc8931

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,15 @@ private function removeAbsolutePathsFromContainer($content)
748748
$filesystem = new Filesystem();
749749

750750
return preg_replace_callback("{'([^']*)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
751-
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__.'/" : "__DIR__.'/";
751+
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__";
752752

753-
return $prefix.rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')."'";
753+
$relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/');
754+
755+
if ($relativePath === '.') {
756+
return $prefix;
757+
}
758+
759+
return $prefix . ".'/" . $relativePath . "'";
754760
}, $content);
755761
}
756762

src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'ROOT_DIR/app/cache/dev/foo'
22
'ROOT_DIR/app/cache/foo'
33
'ROOT_DIR/foo/bar.php'
4+
'ROOT_DIR/app/cache/dev'
45

56
'/some/where/else/foo'
67

src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__DIR__.'/foo'
22
__DIR__.'/../foo'
33
__DIR__.'/../../../foo/bar.php'
4+
__DIR__
45

56
'/some/where/else/foo'
67

0 commit comments

Comments
 (0)