Skip to content

Commit 7118449

Browse files
authored
Merge pull request #53 from nguyenanhung/develop
Release version 1.6.4 - Refactor function makeNewFolder
2 parents df750f2 + 494b3a6 commit 7118449

File tree

6 files changed

+74
-22
lines changed

6 files changed

+74
-22
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ Các hàm này dùng debug
194194
### File Helper
195195

196196
- [x] Helper Function: `formatSizeUnits` - Hàm format 1 int đầu vào thành 1 format để dễ đọc dung lượng file
197-
- [x] Helper Function: `genarateFileIndex` - Tự động tạo nội dung file `index.html`
198-
- [x] Helper Function: `genarateFileHtaccess` - Tự động tạo nội dung file `.htaccess`
199-
- [x] Helper Function: `genarateFileReadme` - Tự động tạo nội dung file `README.md`
200-
- [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`
201-
, `.htaccess`
197+
- [x] Helper Function: `generateFileIndex` - Tự động tạo nội dung file `index.html`
198+
- [x] Helper Function: `generateFileHtaccess` - Tự động tạo nội dung file `.htaccess`
199+
- [x] Helper Function: `generateFileReadme` - Tự động tạo nội dung file `README.md`
200+
- [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`
201+
, `.htaccess`. Tạo thêm file `.gitkeep` nếu tham số thứ 2 được truyền là true
202202
- [x] Helper Function: `new_folder` - Chức năng tương tự với hàm `makeNewFolder`
203203
- [x] Helper Function: `scan_folder` - Quét và lấy ra danh sách các thông tin dữ liệu trong folder
204204
- [x] Helper Function: `getAllFileSizeInFolder` - Get all File size in Folder

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"helpers/money_helper.php",
7070
"helpers/nanoid_helper.php",
7171
"helpers/number_helper.php",
72+
"helpers/old_polyfill_function.php",
7273
"helpers/paging_helper.php",
7374
"helpers/placeholder_helper.php",
7475
"helpers/request_helper.php",

helpers/env_helper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ function bear_get_env($a)
4343
return '';
4444
}
4545
}
46+
if ( ! function_exists('is_cli')) {
47+
/**
48+
* Is CLI?
49+
*
50+
* Test to see if a request was made from the command line.
51+
*
52+
* @return bool
53+
*/
54+
function is_cli()
55+
{
56+
return (PHP_SAPI === 'cli' or defined('STDIN'));
57+
}
58+
}

helpers/file_helper.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ function formatSizeUnits($bytes)
120120
return $bytes;
121121
}
122122
}
123-
if (!function_exists('genarateFileIndex')) {
123+
if ( ! function_exists('generateFileIndex')) {
124124
/**
125-
* Function genarateFileIndex
125+
* Function generateFileIndex
126126
*
127127
* @param string $file_path
128128
* @param string $file_name
@@ -132,7 +132,7 @@ function formatSizeUnits($bytes)
132132
* @copyright: 713uk13m <[email protected]>
133133
* @time : 09/11/2021 55:13
134134
*/
135-
function genarateFileIndex($file_path = '', $file_name = 'index.html')
135+
function generateFileIndex($file_path = '', $file_name = 'index.html')
136136
{
137137
if (function_exists('log_message') && function_exists('write_file')) {
138138
if ($file_path !== '') {
@@ -164,9 +164,9 @@ function genarateFileIndex($file_path = '', $file_name = 'index.html')
164164
return false;
165165
}
166166
}
167-
if (!function_exists('genarateFileHtaccess')) {
167+
if ( ! function_exists('generateFileHtaccess')) {
168168
/**
169-
* Function genarateFileHtaccess
169+
* Function generateFileHtaccess
170170
*
171171
* @param string $file_path
172172
* @param string $file_name
@@ -176,7 +176,7 @@ function genarateFileIndex($file_path = '', $file_name = 'index.html')
176176
* @copyright: 713uk13m <[email protected]>
177177
* @time : 09/11/2021 55:51
178178
*/
179-
function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
179+
function generateFileHtaccess($file_path = '', $file_name = '.htaccess')
180180
{
181181
if (function_exists('log_message') && function_exists('write_file')) {
182182
if ($file_path !== '') {
@@ -208,7 +208,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
208208
return false;
209209
}
210210
}
211-
if (!function_exists('genarateFileReadme')) {
211+
if ( ! function_exists('generateFileReadme')) {
212212
/**
213213
* Function genarateFileReadme
214214
*
@@ -220,7 +220,7 @@ function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
220220
* @copyright: 713uk13m <[email protected]>
221221
* @time : 09/15/2021 58:14
222222
*/
223-
function genarateFileReadme($file_path = '', $file_name = 'README.md')
223+
function generateFileReadme($file_path = '', $file_name = 'README.md')
224224
{
225225
if (function_exists('log_message') && function_exists('write_file')) {
226226
if ($file_path !== '') {
@@ -256,13 +256,14 @@ function genarateFileReadme($file_path = '', $file_name = 'README.md')
256256
* Function makeNewFolder
257257
*
258258
* @param string $folderPath
259+
* @param bool $gitkeep
259260
*
260261
* @return bool
261262
* @author : 713uk13m <[email protected]>
262263
* @copyright: 713uk13m <[email protected]>
263264
* @time : 09/11/2021 57:33
264265
*/
265-
function makeNewFolder($folderPath = '')
266+
function makeNewFolder($folderPath = '', $gitkeep = false)
266267
{
267268
if (empty($folderPath)) {
268269
return false;
@@ -271,10 +272,26 @@ function makeNewFolder($folderPath = '')
271272
if (!mkdir($folderPath) && !is_dir($folderPath)) {
272273
throw new RuntimeException(sprintf('Directory "%s" was not created', $folderPath));
273274
}
274-
genarateFileIndex($folderPath);
275-
genarateFileHtaccess($folderPath);
276-
genarateFileReadme($folderPath);
277-
275+
$createIndex = generateFileIndex($folderPath);
276+
$createHtaccess = generateFileHtaccess($folderPath);
277+
$createReadme = generateFileReadme($folderPath);
278+
if (is_cli()) {
279+
if ($createIndex) {
280+
echo "Create file index.html in " . $folderPath . " successfully";
281+
}
282+
if ($createHtaccess) {
283+
echo "Create file .htaccess in " . $folderPath . " successfully";
284+
}
285+
if ($createReadme) {
286+
echo "Create file README.md in " . $folderPath . " successfully";
287+
}
288+
}
289+
if ($gitkeep === true) {
290+
$createGitkeep = touch($folderPath . '/.gitkeep');
291+
if (is_cli() && $createGitkeep) {
292+
echo "Create file .gitkeep in " . $folderPath . " successfully";
293+
}
294+
}
278295
return true;
279296
}
280297

@@ -286,15 +303,16 @@ function makeNewFolder($folderPath = '')
286303
* Function new_folder
287304
*
288305
* @param string $folder
306+
* @param bool $gitkeep
289307
*
290308
* @return bool
291309
* @author : 713uk13m <[email protected]>
292310
* @copyright: 713uk13m <[email protected]>
293311
* @time : 09/11/2021 58:13
294312
*/
295-
function new_folder($folder = '')
313+
function new_folder($folder = '', $gitkeep = false)
296314
{
297-
return makeNewFolder($folder);
315+
return makeNewFolder($folder, $gitkeep);
298316
}
299317
}
300318
if (!function_exists('scan_folder')) {

helpers/old_polyfill_function.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
if ( ! function_exists('genarateFileIndex')) {
4+
function genarateFileIndex($file_path = '', $file_name = 'index.html')
5+
{
6+
return generateFileIndex($file_path, $file_name);
7+
}
8+
}
9+
if ( ! function_exists('genarateFileHtaccess')) {
10+
function genarateFileHtaccess($file_path = '', $file_name = '.htaccess')
11+
{
12+
return generateFileHtaccess($file_path, $file_name);
13+
}
14+
}
15+
if ( ! function_exists('genarateFileReadme')) {
16+
function genarateFileReadme($file_path = '', $file_name = 'README.md')
17+
{
18+
return generateFileReadme($file_path, $file_name);
19+
}
20+
}

src/BaseHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
class BaseHelper
2121
{
22-
const VERSION = '1.6.3';
23-
const LAST_MODIFIED = '2024-04-12';
22+
const VERSION = '1.6.4';
23+
const LAST_MODIFIED = '2024-09-07';
2424
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
2525
const AUTHOR_NAME = 'Hung Nguyen';
2626
const AUTHOR_FULL_NAME = 'Hung Nguyen';

0 commit comments

Comments
 (0)