8000 Merge branch '2.7' into 2.8 · iamluc/symfony@1e4d4ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e4d4ef

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Filesystem] mirror - fix copying content with same name as source/target. .php_cs.dist - simplify config [WebProfilerBundle] fixed TemplateManager when using Twig 2 without compat interfaces
2 parents 86eb10c + 5bf241a commit 1e4d4ef

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

.php_cs.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ return PhpCsFixer\Config::create()
99
'@Symfony' => true,
1010
'@Symfony:risky' => true,
1111
'array_syntax' => array('syntax' => 'long'),
12-
'no_unreachable_default_argument_value' => false,
13-
'braces' => array('allow_single_line_closure' => true),
14-
'heredoc_to_nowdoc' => false,
1512
))
1613
->setRiskyAllowed(true)
1714
->setFinder(

src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function templateExists($template)
127127
}
128128

129129
try {
130-
if ($loader instanceof SourceContextLoaderInterface) {
130+
if ($loader instanceof SourceContextLoaderInterface || method_exists($loader, 'getSourceContext')) {
131131
$loader->getSourceContext($template);
132132
} else {
133133
$loader->getSource($template);

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
444444
{
445445
$targetDir = rtrim($targetDir, '/\\');
446446
$originDir = rtrim($originDir, '/\\');
447+
$originDirLen = strlen($originDir);
447448

448449
// Iterate in destination folder to remove obsolete entries
449450
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
@@ -452,8 +453,9 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
452453
$flags = \FilesystemIterator::SKIP_DOTS;
453454
$deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
454455
}
456+
$targetDirLen = strlen($targetDir);
455457
foreach ($deleteIterator as $file) {
456-
$origin = str_replace($targetDir, $originDir, $file->getPathname());
458+
$origin = $originDir.substr($file->getPathname(), $targetDirLen);
457459
if (!$this->exists($origin)) {
458460
$this->remove($file);
459461
}
@@ -475,7 +477,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
475477
}
476478

477479
foreach ($iterator as $file) {
478-
$target = str_replace($originDir, $targetDir, $file->getPathname());
480+
$target = $targetDir.substr($file->getPathname(), $originDirLen);
479481

480482
if ($copyOnWindows) {
481483
if (is_file($file)) {

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,53 @@ public function testMirrorCopiesRelativeLinkedContents()
10091009
$this->assertEquals('\\' === DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
10101010
}
10111011

1012+
public function testMirrorContentsWithSameNameAsSourceOrTargetWithoutDeleteOption()
1013+
{
1014+
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
1015+
1016+
mkdir($sourcePath);
1017+
touch($sourcePath.'source');
1018+
touch($sourcePath.'target');
1019+
1020+
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
1021+
1022+
$oldPath = getcwd();
1023+
chdir($this->workspace);
1024+
1025+
$this->filesystem->mirror('source', $targetPath);
1026+
1027+
chdir($oldPath);
1028+
1029+
$this->assertTrue(is_dir($targetPath));
1030+
$this->assertFileExists($targetPath.'source');
1031+
$this->assertFileExists($targetPath.'target');
1032+
}
1033+
1034+
public function testMirrorContentsWithSameNameAsSourceOrTargetWithDeleteOption()
1035+
{
1036+
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
1037+
1038+
mkdir($sourcePath);
1039+
touch($sourcePath.'source');
1040+
1041+
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
1042+
1043+
mkdir($targetPath);
1044+
touch($targetPath.'source');
1045+
touch($targetPath.'target');
1046+
1047+
$oldPath = getcwd();
1048+
chdir($this->workspace);
1049+
1050+
$this->filesystem->mirror('source', 'target', null, array('delete' => true));
1051+
1052+
chdir($oldPath);
1053+
1054+
$this->assertTrue(is_dir($targetPath));
1055+
$this->assertFileExists($targetPath.'source');
1056+
$this->assertFileNotExists($targetPath.'target');
1057+
}
1058+
10121059
/**
10131060
* @dataProvider providePathsForIsAbsolutePath
10141061
*/

0 commit comments

Comments
 (0)
0