Skip to content

Commit 0edfc5d

Browse files
Merge branch '4.4' into 5.1
* 4.4: CS fix [travis] use PHP 8.0 to patch return types and run deps=low Update sl_SI translations Don't trigger deprecation for deprecated aliases pointing to deprecated definitions [HttpFoundation] use atomic writes in MockFileSessionStorage [DI] fix param annotation [Config] Add \Symfony\Component\Config\Loader::load() return type Simplify PHP CS Fixer config Rename normalize param
2 parents 0da0af2 + 30b5202 commit 0edfc5d

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

BinaryFileResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ public function sendContent()
297297
return $this;
298298
}
299299

300-
$out = fopen('php://output', 'wb');
301-
$file = fopen($this->file->getPathname(), 'rb');
300+
$out = fopen('php://output', 'w');
301+
$file = fopen($this->file->getPathname(), 'r');
302302

303303
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
304304

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ public function getContent(bool $asResource = false)
15191519

15201520
$this->content = false;
15211521

1522-
return fopen('php://input', 'rb');
1522+
return fopen('php://input', 'r');
15231523
}
15241524

15251525
if ($currentContentIsResource) {

Session/Storage/MockFileSessionStorage.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function save()
102102

103103
try {
104104
if ($data) {
105-
file_put_contents($this->getFilePath(), serialize($data));
105+
$path = $this->getFilePath();
106+
$tmp = $path.bin2hex(random_bytes(6));
107+
file_put_contents($tmp, serialize($data));
108+
rename($tmp, $path);
106109
} else {
107110
$this->destroy();
108111
}
@@ -122,8 +125,11 @@ public function save()
122125
*/
123126
private function destroy(): void
124127
{
125-
if (is_file($this->getFilePath())) {
128+
set_error_handler(static function () {});
129+
try {
126130
unlink($this->getFilePath());
131+
} finally {
132+
restore_error_handler();
127133
}
128134
}
129135

@@ -140,8 +146,14 @@ private function getFilePath(): string
140146
*/
141147
private function read(): void
142148
{
143-
$filePath = $this->getFilePath();
144-
$this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : [];
149+
set_error_handler(static function () {});
150+
try {
151+
$data = file_get_contents($this->getFilePath());
152+
} finally {
153+
restore_error_handler();
154+
}
155+
156+
$this->data = $data ? unserialize($data) : [];
145157

146158
$this->loadSession();
147159
}

0 commit comments

Comments
 (0)