From 494b3a6875540a7d58aac9a2bfce14ee41b025fc Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Sat, 7 Sep 2024 19:41:36 +0700 Subject: [PATCH] Release version 1.6.4 - Refactor function makeNewFolder --- README.md | 10 +++---- composer.json | 1 + helpers/env_helper.php | 13 +++++++++ helpers/file_helper.php | 48 +++++++++++++++++++++---------- helpers/old_polyfill_function.php | 20 +++++++++++++ src/BaseHelper.php | 4 +-- 6 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 helpers/old_polyfill_function.php diff --git a/README.md b/README.md index 7647834..958152e 100644 --- a/README.md +++ b/README.md @@ -194,11 +194,11 @@ Các hàm này dùng debug ### File Helper - [x] Helper Function: `formatSizeUnits` - Hàm format 1 int đầu vào thành 1 format để dễ đọc dung lượng file -- [x] Helper Function: `genarateFileIndex` - Tự động tạo nội dung file `index.html` -- [x] Helper Function: `genarateFileHtaccess` - Tự động tạo nội dung file `.htaccess` -- [x] Helper Function: `genarateFileReadme` - Tự động tạo nội dung file `README.md` -- [x] Helper Function: `makeNewFolder` - Hàm tạo 1 thư mục mới và genre sẵn trong đó 3 file: `README.md`, `index.html` - , `.htaccess` +- [x] Helper Function: `generateFileIndex` - Tự động tạo nội dung file `index.html` +- [x] Helper Function: `generateFileHtaccess` - Tự động tạo nội dung file `.htaccess` +- [x] Helper Function: `generateFileReadme` - Tự động tạo nội dung file `README.md` +- [x] Helper Function: `makeNewFolder` - Hàm tạo 1 thư mục mới và generate sẵn trong đó 3 file: `README.md`, `index.html` + , `.htaccess`. Tạo thêm file `.gitkeep` nếu tham số thứ 2 được truyền là true - [x] Helper Function: `new_folder` - Chức năng tương tự với hàm `makeNewFolder` - [x] Helper Function: `scan_folder` - Quét và lấy ra danh sách các thông tin dữ liệu trong folder - [x] Helper Function: `getAllFileSizeInFolder` - Get all File size in Folder diff --git a/composer.json b/composer.json index c0e64bd..edee1fc 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ "helpers/money_helper.php", "helpers/nanoid_helper.php", "helpers/number_helper.php", + "helpers/old_polyfill_function.php", "helpers/paging_helper.php", "helpers/placeholder_helper.php", "helpers/request_helper.php", diff --git a/helpers/env_helper.php b/helpers/env_helper.php index cc07294..b2d4f51 100644 --- a/helpers/env_helper.php +++ b/helpers/env_helper.php @@ -43,3 +43,16 @@ function bear_get_env($a) return ''; } } +if ( ! function_exists('is_cli')) { + /** + * Is CLI? + * + * Test to see if a request was made from the command line. + * + * @return bool + */ + function is_cli() + { + return (PHP_SAPI === 'cli' or defined('STDIN')); + } +} diff --git a/helpers/file_helper.php b/helpers/file_helper.php index 055bc3e..c823a6a 100644 --- a/helpers/file_helper.php +++ b/helpers/file_helper.php @@ -120,9 +120,9 @@ function formatSizeUnits($bytes) return $bytes; } } -if (!function_exists('genarateFileIndex')) { +if ( ! function_exists('generateFileIndex')) { /** - * Function genarateFileIndex + * Function generateFileIndex * * @param string $file_path * @param string $file_name @@ -132,7 +132,7 @@ function formatSizeUnits($bytes) * @copyright: 713uk13m * @time : 09/11/2021 55:13 */ - function genarateFileIndex($file_path = '', $file_name = 'index.html') + function generateFileIndex($file_path = '', $file_name = 'index.html') { if (function_exists('log_message') && function_exists('write_file')) { if ($file_path !== '') { @@ -164,9 +164,9 @@ function genarateFileIndex($file_path = '', $file_name = 'index.html') return false; } } -if (!function_exists('genarateFileHtaccess')) { +if ( ! function_exists('generateFileHtaccess')) { /** - * Function genarateFileHtaccess + * Function generateFileHtaccess * * @param string $file_path * @param string $file_name @@ -176,7 +176,7 @@ function genarateFileIndex($file_path = '', $file_name = 'index.html') * @copyright: 713uk13m * @time : 09/11/2021 55:51 */ - function genarateFileHtaccess($file_path = '', $file_name = '.htaccess') + function generateFileHtaccess($file_path = '', $file_name = '.htaccess') { if (function_exists('log_message') && function_exists('write_file')) { if ($file_path !== '') { @@ -208,7 +208,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess') return false; } } -if (!function_exists('genarateFileReadme')) { +if ( ! function_exists('generateFileReadme')) { /** * Function genarateFileReadme * @@ -220,7 +220,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess') * @copyright: 713uk13m * @time : 09/15/2021 58:14 */ - function genarateFileReadme($file_path = '', $file_name = 'README.md') + function generateFileReadme($file_path = '', $file_name = 'README.md') { if (function_exists('log_message') && function_exists('write_file')) { if ($file_path !== '') { @@ -256,13 +256,14 @@ function genarateFileReadme($file_path = '', $file_name = 'README.md') * Function makeNewFolder * * @param string $folderPath + * @param bool $gitkeep * * @return bool * @author : 713uk13m * @copyright: 713uk13m * @time : 09/11/2021 57:33 */ - function makeNewFolder($folderPath = '') + function makeNewFolder($folderPath = '', $gitkeep = false) { if (empty($folderPath)) { return false; @@ -271,10 +272,26 @@ function makeNewFolder($folderPath = '') if (!mkdir($folderPath) && !is_dir($folderPath)) { throw new RuntimeException(sprintf('Directory "%s" was not created', $folderPath)); } - genarateFileIndex($folderPath); - genarateFileHtaccess($folderPath); - genarateFileReadme($folderPath); - + $createIndex = generateFileIndex($folderPath); + $createHtaccess = generateFileHtaccess($folderPath); + $createReadme = generateFileReadme($folderPath); + if (is_cli()) { + if ($createIndex) { + echo "Create file index.html in " . $folderPath . " successfully"; + } + if ($createHtaccess) { + echo "Create file .htaccess in " . $folderPath . " successfully"; + } + if ($createReadme) { + echo "Create file README.md in " . $folderPath . " successfully"; + } + } + if ($gitkeep === true) { + $createGitkeep = touch($folderPath . '/.gitkeep'); + if (is_cli() && $createGitkeep) { + echo "Create file .gitkeep in " . $folderPath . " successfully"; + } + } return true; } @@ -286,15 +303,16 @@ function makeNewFolder($folderPath = '') * Function new_folder * * @param string $folder + * @param bool $gitkeep * * @return bool * @author : 713uk13m * @copyright: 713uk13m * @time : 09/11/2021 58:13 */ - function new_folder($folder = '') + function new_folder($folder = '', $gitkeep = false) { - return makeNewFolder($folder); + return makeNewFolder($folder, $gitkeep); } } if (!function_exists('scan_folder')) { diff --git a/helpers/old_polyfill_function.php b/helpers/old_polyfill_function.php new file mode 100644 index 0000000..56e5afd --- /dev/null +++ b/helpers/old_polyfill_function.php @@ -0,0 +1,20 @@ +