UtilsPHP.php in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2
File
src/Flmngr/FileUploaderServer/lib/file/UtilsPHP.php
View source
<?php
namespace Drupal\n1ed\Flmngr\FileUploaderServer\lib\file;
use Exception;
class UtilsPHP {
public static function cleanDirectory($dir) {
UtilsPHP::delete($dir, FALSE);
}
public static function delete($dirOrFile, $deleteSelfDir = TRUE) {
if (is_file($dirOrFile)) {
$result = is_dir($dirOrFile) ? rmdir($dirOrFile) : unlink($dirOrFile);
if (!$result) {
throw new Exception('Unable to delete file: ' . $dirOrFile);
}
}
elseif (is_dir($dirOrFile)) {
$scan = glob(rtrim($dirOrFile, DIRECTORY_SEPARATOR) . '/*');
foreach ($scan as $path) {
UtilsPHP::delete($path);
}
if ($deleteSelfDir) {
if (!rmdir($dirOrFile)) {
throw new Exception('Unable to delete directory: ' . $dirOrFile);
}
}
}
}
public static function copyFile($src, $dst) {
if (!copy($src, $dst)) {
throw new Exception('Unable to copy file ' . $src . ' to ' . $dst);
}
}
public static function normalizeNoEndSeparator($path) {
return rtrim($path, DIRECTORY_SEPARATOR);
}
}