From 079786e42dec0397ddb30654332d89c8007794dd Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 5 Aug 2020 14:01:26 +0200 Subject: [PATCH] Add type-safe wrapper around realpath --- MD_STD.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index eeeba8a..77a14dd 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -34,6 +34,22 @@ class MD_STD { } + /** + * Returns the real path of a relative file path. Throws an error rather than + * returning the default false. + * + * @param string $path File path to convert. + * + * @return string + */ + public static function realpath(string $path):string { + + $output = realpath($path); + if (!is_string($output)) throw new MDFileDoesNotExist("The file {$path} does not exist or is not readable."); + return $output; + + } + /** * Gets contents of a folder. *