diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-27 10:56:24 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-28 20:21:34 +0200 |
commit | c832f91ca41490f69f478045c86038f9ef4a5cb5 (patch) | |
tree | b371e504c04660bbabb79721c5db7b086888ec01 /app/fn/fn.php | |
parent | d66de69ba57f00079ab8d5e4b9a1d1f73093e76a (diff) | |
download | wcms-c832f91ca41490f69f478045c86038f9ef4a5cb5.tar.gz wcms-c832f91ca41490f69f478045c86038f9ef4a5cb5.zip |
move fonts into media
move global css into media
Diffstat (limited to 'app/fn/fn.php')
-rw-r--r-- | app/fn/fn.php | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/app/fn/fn.php b/app/fn/fn.php index 4ad0c6b..f20c8c6 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -377,28 +377,56 @@ function secrethash(string $token): string /** - * Check if a file is accessible or can be writen - * @param string $path file path to check - * @param bool $createdir create directory if does not exist - * @throws \InvalidArgumentException if : - * parent directory does not exist | is not writable | file exist and not writable + * Check if dir exist. If not, create it + * + * @param string $dir Directory to check + * @param bool $createdir create dir in case of non existence default is true + * @return bool return true if the dir already exist or was created succesfullt. Otherwise return false + * @throws \InvalidArgumentException If folder creation is impossible or if directory doeas not exist */ -function accessfile(string $path, bool $createdir = false) +function dircheck(string $dir, bool $createdir = true): bool { - $dir = dirname($path); if (!is_dir($dir)) { if ($createdir) { - if (!mkdir($dir)) { - throw new \InvalidArgumentException("Cannot create directory : $dir"); + $parent = dirname($dir); + if (dircheck($parent)) { + if (mkdir($dir)) { + return true; + } else { + throw new \InvalidArgumentException("Cannot create directory : $dir"); + } + } else { + return false; } } else { throw new \InvalidArgumentException("Directory '$dir' does not exist."); } + } else { + return true; } - if (!is_writable($dir)) { - throw new \InvalidArgumentException("Directory '$dir' is not writable."); - } - if (is_file($path) && !is_writable($path)) { - throw new \InvalidArgumentException("The file '$path' is not writable."); +} + + +/** + * Check if a file is accessible or can be writen + * @param string $path file path to check + * @param bool $createdir create directory if does not exist + * @return bool If no error occured + * @throws \InvalidArgumentException if : + * parent directory does not exist | is not writable | file exist and not writable + */ +function accessfile(string $path, bool $createdir = false): bool +{ + $dir = dirname($path); + if (dircheck($dir, $createdir)) { + if (!is_writable($dir)) { + throw new \InvalidArgumentException("Directory '$dir' is not writable."); + } + if (is_file($path) && !is_writable($path)) { + throw new \InvalidArgumentException("The file '$path' is not writable."); + } + return true; + } else { + return false; } } |