From 44d89aabe6b87d0b97b9494a6589568f3f536ab4 Mon Sep 17 00:00:00 2001 From: mirzaev Date: Tue, 4 Nov 2025 02:35:57 +0700 Subject: [PATCH] created --- .gitignore | 3 ++ README.md | 8 +++- composer.json | 32 ++++++++++++++++ mirzaev/files/system/files.php | 67 ++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 mirzaev/files/system/files.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa366b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +!.gitignore +composer.lock +vendor diff --git a/README.md b/README.md index 0016706..6600e20 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ -# files +# Files +Easy working with files -Easy working with files \ No newline at end of file +## Installation +```bash +composer require mirzaev/files +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..94e2505 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "mirzaev/files", + "description": "Easy working with files", + "homepage": "https://git.svoboda.works/mirzaev/files", + "type": "library", + "keywords": [ + "files" + ], + "readme": "README.md", + "license": "WTFPL", + "authors": [ + { + "name": "Arsen Mirzaev Tatyano-Muradovich", + "email": "arsen@mirzaev.sexy", + "homepage": "https://mirzaev.sexy", + "role": "Creator" + } + ], + "support": { + "wiki": "https://git.svoboda.works/mirzaev/files/wiki", + "issues": "https://git.svoboda.works/mirzaev/files/issues" + }, + "require": { + "php": "^8.4" + }, + "autoload": { + "psr-4": { + "mirzaev\\files\\": "mirzaev/files/system" + } + } +} + diff --git a/mirzaev/files/system/files.php b/mirzaev/files/system/files.php new file mode 100644 index 0000000..bc1a894 --- /dev/null +++ b/mirzaev/files/system/files.php @@ -0,0 +1,67 @@ + + */ +class files +{ + /** + * Delete + * + * Delete files recursively + * + * @param string $directory Directory + * @param array &$errors Registry of errors + * + * @throws exception_runtime if directory does not exists + * + * @return void + */ + public static function delete(string $directory, array &$errors = []): void + { + try { + if (file_exists($directory)) { + // Directory exists + + // Deleting descendant files and directories (enter to the recursion) + foreach (scandir($directory) as $file) { + if ($file === '.' || $file === '..') continue; + else if (is_dir("$directory/$file")) static::delete("$directory/$file", $errors); + else unlink("$directory/$file"); + } + + // Deleting the directory + rmdir($directory); + + // Exit (success) + return; + } else throw new exception_runtime('Directory does not exist'); + } catch (exception $e) { + // Writing to the registry of errors + $errors[] = [ + 'text' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'stack' => $e->getTrace() + ]; + } + + // Exit (fail) + return; + } +} +