Update functions_cli.php

This commit is contained in:
Roman Kelesidis 2025-06-09 14:06:08 +03:00
commit f9f761277c

View file

@ -15,13 +15,18 @@ if (!defined('BB_ROOT')) {
* Remove target file * Remove target file
* *
* @param string $file Path to file * @param string $file Path to file
* @param bool $withoutOutput Hide output
*/ */
function removeFile(string $file): void function removeFile(string $file, bool $withoutOutput = false): void
{ {
if (unlink($file)) { if (unlink($file)) {
echo "- File removed: $file" . PHP_EOL; if ($withoutOutput === false) {
echo "- File removed: $file" . PHP_EOL;
}
} else { } else {
echo "- File cannot be removed: $file" . PHP_EOL; if ($withoutOutput === false) {
echo "- File cannot be removed: $file" . PHP_EOL;
}
exit; exit;
} }
} }
@ -30,8 +35,9 @@ function removeFile(string $file): void
* Remove folder (recursively) * Remove folder (recursively)
* *
* @param string $dir Path to folder * @param string $dir Path to folder
* @param bool $withoutOutput Hide output
*/ */
function removeDir(string $dir): void function removeDir(string $dir, bool $withoutOutput = false): void
{ {
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); $it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
@ -40,14 +46,18 @@ function removeDir(string $dir): void
if ($file->isDir()) { if ($file->isDir()) {
removeDir($file->getPathname()); removeDir($file->getPathname());
} else { } else {
removeFile($file->getPathname()); removeFile($file->getPathname(), $withoutOutput);
} }
} }
if (rmdir($dir)) { if (rmdir($dir)) {
echo "- Folder removed: $dir" . PHP_EOL; if ($withoutOutput === false) {
echo "- Folder removed: $dir" . PHP_EOL;
}
} else { } else {
echo "- Folder cannot be removed: $dir" . PHP_EOL; if ($withoutOutput === false) {
echo "- Folder cannot be removed: $dir" . PHP_EOL;
}
exit; exit;
} }
} }