Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitfb498a3

Browse files
committed
[Filesystem] Add third argument$lockFile toFilesystem::appendToFile()
1 parentee6bbb2 commitfb498a3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add`Path` class
8+
*`Filesystem::appendToFile()` now accepts a third argument`$lockFile`
89

910
5.0.0
1011
-----

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,11 @@ public function dumpFile(string $filename, $content)
692692
* Appends content to an existing file.
693693
*
694694
* @param string|resource $content The content to append
695+
* @param bool $lockFile Lock the file when writing to it
695696
*
696697
* @throws IOException If the file is not writable
697698
*/
698-
publicfunctionappendToFile(string$filename,$content)
699+
publicfunctionappendToFile(string$filename,$content/*,bool $lockFile = false*/)
699700
{
700701
if (\is_array($content)) {
701702
thrownew \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.',__METHOD__));
@@ -707,7 +708,14 @@ public function appendToFile(string $filename, $content)
707708
$this->mkdir($dir);
708709
}
709710

710-
if (false ===self::box('file_put_contents',$filename,$content, \FILE_APPEND)) {
711+
$flags = \FILE_APPEND;
712+
$lockFile =\func_num_args() >2 ?\func_get_arg(2) :'';
713+
714+
if ($lockFile ===true) {
715+
$flags |= \LOCK_EX;
716+
}
717+
718+
if (false ===self::box('file_put_contents',$filename,$content,$flags)) {
711719
thrownewIOException(sprintf('Failed to write file "%s":',$filename).self::$lastError,0,null,$filename);
712720
}
713721
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp