Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0eaf9d2

Browse filesBrowse files
thewilkybarkidfabpot
authored andcommitted
[Filesystem] Support resources and deprecate using arrays in dumpFile() and appendToFile()
1 parent 5f737e8 commit 0eaf9d2
Copy full SHA for 0eaf9d2

File tree

4 files changed

+89
-11
lines changed
Filter options

4 files changed

+89
-11
lines changed

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ EventDispatcher
6565

6666
* The `TraceableEventDispatcherInterface` has been removed.
6767

68+
Filesystem
69+
----------
70+
71+
* The `Filesystem::dumpFile()` method no longer supports arrays in the `$content` argument.
72+
* The `Filesystem::appendToFile()` method no longer supports arrays in the `$content` argument.
73+
6874
Finder
6975
------
7076

‎src/Symfony/Component/Filesystem/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* support for passing arrays to `Filesystem::dumpFile()` is deprecated and will be removed in 5.0
8+
* support for passing arrays to `Filesystem::appendToFile()` is deprecated and will be removed in 5.0
9+
410
4.0.0
511
-----
612

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,17 @@ public function tempnam($dir, $prefix)
670670
/**
671671
* Atomically dumps content into a file.
672672
*
673-
* @param string $filename The file to be written to
674-
* @param string $content The data to write into the file
673+
* @param string $filename The file to be written to
674+
* @param string|resource $content The data to write into the file
675675
*
676676
* @throws IOException if the file cannot be written to
677677
*/
678678
public function dumpFile($filename, $content)
679679
{
680+
if (\is_array($content)) {
681+
@trigger_error(sprintf('Calling "%s()" with an array in the $content argument is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
682+
}
683+
680684
$dir = \dirname($filename);
681685

682686
if (!is_dir($dir)) {
@@ -703,13 +707,17 @@ public function dumpFile($filename, $content)
703707
/**
704708
* Appends content to an existing file.
705709
*
706-
* @param string $filename The file to which to append content
707-
* @param string $content The content to append
710+
* @param string $filename The file to which to append content
711+
* @param string|resource $content The content to append
708712
*
709713
* @throws IOException If the file is not writable
710714
*/
711715
public function appendToFile($filename, $content)
712716
{
717+
if (\is_array($content)) {
718+
@trigger_error(sprintf('Calling "%s()" with an array in the $content argument is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
719+
}
720+
713721
$dir = \dirname($filename);
714722

715723
if (!is_dir($dir)) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
+65-7Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,21 +1334,21 @@ public function testMirrorContentsWithSameNameAsSourceOrTargetWithDeleteOption()
13341334

13351335
public function testMirrorWithCustomIterator()
13361336
{
1337-
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
1337+
$sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
13381338
mkdir($sourcePath);
13391339

1340-
$file = $sourcePath.DIRECTORY_SEPARATOR.'file';
1340+
$file = $sourcePath.\DIRECTORY_SEPARATOR.'file';
13411341
file_put_contents($file, 'FILE');
13421342

1343-
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
1343+
$targetPath = $this->workspace.\DIRECTORY_SEPARATOR.'target'.\DIRECTORY_SEPARATOR;
13441344

13451345
$splFile = new \SplFileInfo($file);
13461346
$iterator = new \ArrayObject(array($splFile));
13471347

13481348
$this->filesystem->mirror($sourcePath, $targetPath, $iterator);
13491349

13501350
$this->assertTrue(is_dir($targetPath));
1351-
$this->assertFileEquals($file, $targetPath.DIRECTORY_SEPARATOR.'file');
1351+
$this->assertFileEquals($file, $targetPath.\DIRECTORY_SEPARATOR.'file');
13521352
}
13531353

13541354
/**
@@ -1357,14 +1357,14 @@ public function testMirrorWithCustomIterator()
13571357
*/
13581358
public function testMirrorWithCustomIteratorWithRelativePath()
13591359
{
1360-
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
1361-
$realSourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
1360+
$sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
1361+
$realSourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
13621362
mkdir($realSourcePath);
13631363

13641364
$file = $realSourcePath.'file';
13651365
file_put_contents($file, 'FILE');
13661366

1367-
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
1367+
$targetPath = $this->workspace.\DIRECTORY_SEPARATOR.'target'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'target'.\DIRECTORY_SEPARATOR;
13681368

13691369
$splFile = new \SplFileInfo($file);
13701370
$iterator = new \ArrayObject(array($splFile));
@@ -1518,6 +1518,10 @@ public function testDumpFile()
15181518
}
15191519
}
15201520

1521+
/**
1522+
* @group legacy
1523+
* @expectedDeprecation Calling "Symfony\Component\Filesystem\Filesystem::dumpFile()" with an array in the $content argument is deprecated since Symfony 4.3.
1524+
*/
15211525
public function testDumpFileWithArray()
15221526
{
15231527
$filename = $this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'baz.txt';
@@ -1600,6 +1604,60 @@ public function testAppendToFile()
16001604
}
16011605
}
16021606

1607+
/**
1608+
* @group legacy
1609+
* @expectedDeprecation Calling "Symfony\Component\Filesystem\Filesystem::appendToFile()" with an array in the $content argument is deprecated since Symfony 4.3.
1610+
*/
1611+
public function testAppendToFileWithArray()
1612+
{
1613+
$filename = $this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.txt';
1614+
1615+
// skip mode check on Windows
1616+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1617+
$oldMask = umask(0002);
1618+
}
1619+
1620+
$this->filesystem->dumpFile($filename, 'foo');
1621+
1622+
$this->filesystem->appendToFile($filename, array('bar'));
1623+
1624+
$this->assertFileExists($filename);
1625+
$this->assertStringEqualsFile($filename, 'foobar');
1626+
1627+
// skip mode check on Windows
1628+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1629+
$this->assertFilePermissions(664, $filename);
1630+
umask($oldMask);
1631+
}
1632+
}
1633+
1634+
public function testAppendToFileWithResource()
1635+
{
1636+
$filename = $this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.txt';
1637+
1638+
// skip mode check on Windows
1639+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1640+
$oldMask = umask(0002);
1641+
}
1642+
1643+
$this->filesystem->dumpFile($filename, 'foo');
1644+
1645+
$resource = fopen('php://memory', 'rw');
1646+
fwrite($resource, 'bar');
1647+
fseek($resource, 0);
1648+
1649+
$this->filesystem->appendToFile($filename, $resource);
1650+
1651+
$this->assertFileExists($filename);
1652+
$this->assertStringEqualsFile($filename, 'foobar');
1653+
1654+
// skip mode check on Windows
1655+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1656+
$this->assertFilePermissions(664, $filename);
1657+
umask($oldMask);
1658+
}
1659+
}
1660+
16031661
public function testAppendToFileWithScheme()
16041662
{
16051663
$scheme = 'file://';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.