Skip to content

Commit

Permalink
Merge pull request #53 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Release version 1.6.4 - Refactor function makeNewFolder
  • Loading branch information
nguyenanhung authored Sep 7, 2024
2 parents df750f2 + 494b3a6 commit 7118449
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 22 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions helpers/env_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
48 changes: 33 additions & 15 deletions helpers/file_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -132,7 +132,7 @@ function formatSizeUnits($bytes)
* @copyright: 713uk13m <[email protected]>
* @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 !== '') {
Expand Down Expand Up @@ -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
Expand All @@ -176,7 +176,7 @@ function genarateFileIndex($file_path = '', $file_name = 'index.html')
* @copyright: 713uk13m <[email protected]>
* @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 !== '') {
Expand Down Expand Up @@ -208,7 +208,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
return false;
}
}
if (!function_exists('genarateFileReadme')) {
if ( ! function_exists('generateFileReadme')) {
/**
* Function genarateFileReadme
*
Expand All @@ -220,7 +220,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
* @copyright: 713uk13m <[email protected]>
* @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 !== '') {
Expand Down Expand Up @@ -256,13 +256,14 @@ function genarateFileReadme($file_path = '', $file_name = 'README.md')
* Function makeNewFolder
*
* @param string $folderPath
* @param bool $gitkeep
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/11/2021 57:33
*/
function makeNewFolder($folderPath = '')
function makeNewFolder($folderPath = '', $gitkeep = false)
{
if (empty($folderPath)) {
return false;
Expand All @@ -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;
}

Expand All @@ -286,15 +303,16 @@ function makeNewFolder($folderPath = '')
* Function new_folder
*
* @param string $folder
* @param bool $gitkeep
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @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')) {
Expand Down
20 changes: 20 additions & 0 deletions helpers/old_polyfill_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

if ( ! function_exists('genarateFileIndex')) {
function genarateFileIndex($file_path = '', $file_name = 'index.html')
{
return generateFileIndex($file_path, $file_name);
}
}
if ( ! function_exists('genarateFileHtaccess')) {
function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
{
return generateFileHtaccess($file_path, $file_name);
}
}
if ( ! function_exists('genarateFileReadme')) {
function genarateFileReadme($file_path = '', $file_name = 'README.md')
{
return generateFileReadme($file_path, $file_name);
}
}
4 changes: 2 additions & 2 deletions src/BaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
class BaseHelper
{
const VERSION = '1.6.3';
const LAST_MODIFIED = '2024-04-12';
const VERSION = '1.6.4';
const LAST_MODIFIED = '2024-09-07';
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_FULL_NAME = 'Hung Nguyen';
Expand Down

0 comments on commit 7118449

Please sign in to comment.