Add wrapper around file_put_contents
This commit is contained in:
parent
94dfa17290
commit
cd46a3ec73
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user