Skip to content

Commit

Permalink
Merge pull request #16 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nguyenanhung authored Mar 20, 2023
2 parents fdc6ba3 + bc57e0d commit 2c281cc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Dưới đây là danh sách các Helper được hỗ trợ trong bộ thư vi

- [x] Helper Function: `isEmpty ` - Kiểm tra 1 input đầu vào xem có phải là rỗng hay không
- [x] Helper Function: `defaultCompressHtmlOutput ` - Compress HTML output, default configure
- [x] Helper Function: `generateRandomUniqueId ` - Tạo 1 chuỗi Unique ID ngẫu nhiên, sử dụng UUID
- [x] Helper Function: `generateRandomNanoUniqueId ` - Tạo 1 chuỗi Unique ID ngẫu nhiên, sử dụng NanoID

### Database Helper

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"nguyenanhung/basic-miscellaneous-helper": "^2.0 || ^1.0"
},
"require-dev": {
"nguyenanhung/nanoid-helper": "^2.0 || ^1.0",
"nguyenanhung/json-helper": "^2.0 || ^1.0",
"nguyenanhung/image": "^3.0 || ^2.0 || ^1.0"
},
"autoload": {
Expand Down
19 changes: 18 additions & 1 deletion helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function smart_bear_basic_helper_version()
function smart_bear_basic_helper_author()
{
$helper = new \nguyenanhung\CodeIgniter\BasicHelper\BaseHelper();

return $helper->getAuthor();
}
}
Expand Down Expand Up @@ -74,3 +73,21 @@ function defaultCompressHtmlOutput($html = '')
return preg_replace($search, $replace, $html);
}
}
if (!function_exists('generateRandomUniqueId')) {
function generateRandomUniqueId()
{
$uniqid = uniqid('-bear-', true);
$uniqid = trim(str_replace('.', '', $uniqid));

return date('Ymd') . '-' . generate_uuid_v4() . $uniqid;
}
}
if (!function_exists('generateRandomNanoUniqueId')) {
function generateRandomNanoUniqueId()
{
$uniqid = uniqid('-bear-', true);
$uniqid = trim(str_replace('.', '', $uniqid));

return date('Ymd') . '-' . randomNanoId(16) . $uniqid;
}
}
11 changes: 5 additions & 6 deletions helpers/nanoid_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
/**
* Function randomNanoId
*
* @param int $size
* @param $size
* @param $prefix
*
* @return string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/14/2021 07:22
* @time : 20/03/2023 48:05
*/
function randomNanoId($size = 21)
function randomNanoId($size = 21, $prefix = 'Bear-')
{
if (class_exists('Hidehalo\Nanoid\Client')) {
$client = new Hidehalo\Nanoid\Client();

return $client->generateId($size);
}

return uniqid('Bear_', true);
return uniqid($prefix, true);
}
}
1 change: 0 additions & 1 deletion helpers/uuid_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function generate_uuid_v3($namespace, $name)
substr($hash, 20, 12));
}
}

if (!function_exists('generate_uuid_v4')) {
/**
* Function generate_uuid_v4
Expand Down
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.3.1';
const LAST_MODIFIED = '2023-03-10';
const VERSION = '1.3.3';
const LAST_MODIFIED = '2023-03-20';
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_FULL_NAME = 'Hung Nguyen';
Expand Down
6 changes: 2 additions & 4 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,7 @@ protected function validateRequiredWith($field, $value, $params, $fields)
}
}
// if we have conditionally required fields
if ($conditionallyReq && (is_null($value) ||
is_string($value) && trim($value) === '')) {
if ($conditionallyReq && (is_null($value) || (is_string($value) && trim($value) === ''))) {
return false;
}

Expand Down Expand Up @@ -1089,8 +1088,7 @@ protected function validateRequiredWithout($field, $value, $params, $fields)
}
}
// if we have conditionally required fields
if ($conditionallyReq && (is_null($value) ||
is_string($value) && trim($value) === '')) {
if ($conditionallyReq && (is_null($value) || (is_string($value) && trim($value) === ''))) {
return false;
}

Expand Down

0 comments on commit 2c281cc

Please sign in to comment.