Add wrapper around file_put_contents

This commit is contained in:
Joshua Ramon Enslin 2024-06-24 16:53:01 +02:00
parent 94dfa17290
commit cd46a3ec73
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -33,6 +33,27 @@ final class MD_STD {
}
/**
* Wrapper around file_put_contents, that provides catches errors on it and returns
* with type safety.
*
* @param non-empty-string $filename Filepath of the file to read.
* @param string $data Data to write.
*
* @return integer
*/
public static function file_put_contents(string $filename, string $data):int {
$status = \file_put_contents($filename, $data);
if ($status === false) {
throw new MDFileIsNotWritable("File {$filename} is not writable");
}
return $status;
}
/**
* Returns the real path of a relative file path. Throws an error rather than
* returning the default false.