[UTIL] Add option for setting a file suffix on TemporaryFile constructor and add missing TemporaryFileException

This commit is contained in:
2021-04-29 20:27:41 +00:00
parent a165e533bb
commit 29457ef50d
2 changed files with 41 additions and 1 deletions

View File

@@ -19,6 +19,8 @@
namespace App\Util;
use App\Util\Exception\TemporaryFileException;
/**
* Class oriented at providing automatic temporary file handling.
*
@@ -39,9 +41,10 @@ class TemporaryFile extends \SplFileInfo
*/
public function __construct(
?string $prefix = null,
?string $suffix = null,
?string $mode = null
) {
$filename = tempnam(sys_get_temp_dir(), $prefix ?? 'gs-php');
$filename = tempnam(sys_get_temp_dir(), $prefix ?? 'gs-php') . ($suffix ?? '');
if ($filename === false) {
throw new TemporaryFileException('Could not create file: ' . $filename);