From: Vincent Vanwaelscappel Date: Tue, 17 May 2022 15:46:55 +0000 (+0200) Subject: wip #5220 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d454434b8551deff5f19be89b95df43a67d942e1;p=cubist_util.git wip #5220 --- diff --git a/src/Files/Files.php b/src/Files/Files.php index 08e528b..92066dd 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -276,5 +276,18 @@ class Files return $time; } + /** + * @param ...$files string + * @return string|null + */ + public static function firstThatExists(...$files){ + foreach ($files as $file) { + if(file_exists($file)){ + return $file; + } + } + return null; + } + } \ No newline at end of file diff --git a/src/PHP.php b/src/PHP.php index 047dfec..bcbc8f3 100644 --- a/src/PHP.php +++ b/src/PHP.php @@ -61,4 +61,19 @@ class PHP } return null; } + + /** + * @param $expression + * @param $return + * @return string|void + */ + public static function var_export($expression, $return = false) + { + $export = var_export($expression, TRUE); + $export = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $export); + $array = preg_split("/\r\n|\n|\r/", $export); + $array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array); + $export = implode(PHP_EOL, array_filter(["["] + $array)); + if ($return) return $export; else echo $export; + } }