Add function unlink_if_exists

This commit is contained in:
Joshua Ramon Enslin 2023-04-14 14:13:09 +02:00
parent 23232f4e6a
commit 66a5b77b51
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -94,6 +94,25 @@ final class MD_STD {
}
/**
* Wrapper around unlink, that explicitly deletes files when existent, but
* accepts if they don't. An error is thrown if the files could not be
* deleted for other reasons.
*
* @see https://www.php.net/manual/en/function.unlink.php
*
* @param non-empty-string $filename File path.
*
* @return void
*/
public static function unlink_if_exists(string $filename):void {
if (!\file_exists($filename)) return;
self::unlink($filename);
}
/**
* Gets contents of a folder.
*