From d28c245a1aa5a78b11518d587f7871786b7e61b1 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 21 Dec 2020 14:50:28 +0100 Subject: [PATCH] Add wrapper around mkdir, that throws an exception on errors --- MD_STD.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index 8fa0ae8..915d9bb 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -49,6 +49,27 @@ final class MD_STD { } + /** + * Wrapper around mkdir, that throws an exception, if the folder cannot be + * created. + * + * @see https://www.php.net/manual/en/function.mkdir.php + * + * @param string $pathname The directory path. + * @param integer $mode Permissions. + * @param boolean $recursive Allows the creation of nested directories + * specified in the pathname. + * + * @return void + */ + public static function mkdir(string $pathname, int $mode = 0775, bool $recursive = false) { + + if (\mkdir($pathname, $mode, $recursive) === false) { + throw new Exception("Failed to create directory: $pathname"); + } + + } + /** * Gets contents of a folder. *