Skip to content

Commit b12ea29

Browse files
add filename argument to create tmp file
1 parent 57a2f45 commit b12ea29

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/TempFile.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class TempFile
1414
* @return FileInfo The FileInfo object representing the temporary file
1515
* @throws RuntimeException If unable to decode base64 data or create the temporary file
1616
*/
17-
public static function fromBase64(string $base64Data): FileInfo
17+
public static function fromBase64(string $base64Data, ?string $filename = null): FileInfo
1818
{
1919
if (strncmp($base64Data, 'data:', 5) === 0) {
2020
$decodedData = file_get_contents($base64Data);
@@ -26,7 +26,7 @@ public static function fromBase64(string $base64Data): FileInfo
2626
throw new RuntimeException('Unable to decode base64 data.');
2727
}
2828

29-
return self::createTempFileWithContent($decodedData);
29+
return self::createTempFileWithContent($decodedData, $filename);
3030
}
3131

3232
/**
@@ -36,9 +36,9 @@ public static function fromBase64(string $base64Data): FileInfo
3636
* @return FileInfo The FileInfo object representing the temporary file
3737
* @throws RuntimeException If unable to create the temporary file
3838
*/
39-
public static function fromBinary(string $data): FileInfo
39+
public static function fromBinary(string $data, ?string $filename = null): FileInfo
4040
{
41-
return self::createTempFileWithContent($data);
41+
return self::createTempFileWithContent($data, $filename);
4242
}
4343

4444
/**
@@ -97,9 +97,9 @@ public static function createTempFile(?string $filename = null): FileInfo
9797
return new FileInfo($tmpFilePath);
9898
}
9999

100-
private static function createTempFileWithContent(string $content): FileInfo
100+
private static function createTempFileWithContent(string $content, ?string $filename = null): FileInfo
101101
{
102-
$file = self::createTempFile();
102+
$file = self::createTempFile($filename);
103103
if (file_put_contents($file->getRealPath(), $content) === false) {
104104
throw new RuntimeException('Unable to write data to temporary file.');
105105
}

0 commit comments

Comments
 (0)