@@ -14,7 +14,7 @@ final class TempFile
14
14
* @return FileInfo The FileInfo object representing the temporary file
15
15
* @throws RuntimeException If unable to decode base64 data or create the temporary file
16
16
*/
17
- public static function fromBase64 (string $ base64Data ): FileInfo
17
+ public static function fromBase64 (string $ base64Data, ? string $ filename = null ): FileInfo
18
18
{
19
19
if (strncmp ($ base64Data , 'data: ' , 5 ) === 0 ) {
20
20
$ decodedData = file_get_contents ($ base64Data );
@@ -26,7 +26,7 @@ public static function fromBase64(string $base64Data): FileInfo
26
26
throw new RuntimeException ('Unable to decode base64 data. ' );
27
27
}
28
28
29
- return self ::createTempFileWithContent ($ decodedData );
29
+ return self ::createTempFileWithContent ($ decodedData, $ filename );
30
30
}
31
31
32
32
/**
@@ -36,9 +36,9 @@ public static function fromBase64(string $base64Data): FileInfo
36
36
* @return FileInfo The FileInfo object representing the temporary file
37
37
* @throws RuntimeException If unable to create the temporary file
38
38
*/
39
- public static function fromBinary (string $ data ): FileInfo
39
+ public static function fromBinary (string $ data, ? string $ filename = null ): FileInfo
40
40
{
41
- return self ::createTempFileWithContent ($ data );
41
+ return self ::createTempFileWithContent ($ data, $ filename );
42
42
}
43
43
44
44
/**
@@ -97,9 +97,9 @@ public static function createTempFile(?string $filename = null): FileInfo
97
97
return new FileInfo ($ tmpFilePath );
98
98
}
99
99
100
- private static function createTempFileWithContent (string $ content ): FileInfo
100
+ private static function createTempFileWithContent (string $ content, ? string $ filename = null ): FileInfo
101
101
{
102
- $ file = self ::createTempFile ();
102
+ $ file = self ::createTempFile ($ filename );
103
103
if (file_put_contents ($ file ->getRealPath (), $ content ) === false ) {
104
104
throw new RuntimeException ('Unable to write data to temporary file. ' );
105
105
}
0 commit comments