From 3a4172d593340d958942a8f8590d2ab205fdf282 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Fri, 10 Mar 2023 09:39:09 +0700 Subject: [PATCH 1/2] Refactor Validator --- src/BaseHelper.php | 2 +- src/Validator.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/BaseHelper.php b/src/BaseHelper.php index c0f99cf..04bbd58 100644 --- a/src/BaseHelper.php +++ b/src/BaseHelper.php @@ -19,7 +19,7 @@ */ class BaseHelper { - const VERSION = '1.3.1'; + const VERSION = '1.3.2'; const LAST_MODIFIED = '2023-03-10'; const PROJECT_NAME = 'CodeIgniter - Basic Helper'; const AUTHOR_NAME = 'Hung Nguyen'; diff --git a/src/Validator.php b/src/Validator.php index 62db8c1..1e2ab10 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -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; } @@ -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; } From bc57e0d24558761619224ae1198d5ca45bcc4771 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Mon, 20 Mar 2023 11:53:53 +0700 Subject: [PATCH 2/2] Update Common Helper --- README.md | 2 ++ composer.json | 2 ++ helpers/common_helper.php | 19 ++++++++++++++++++- helpers/nanoid_helper.php | 11 +++++------ helpers/uuid_helper.php | 1 - src/BaseHelper.php | 4 ++-- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 458a17c..8715fb4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index a15b5ac..ca10cfb 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/helpers/common_helper.php b/helpers/common_helper.php index 1c954d5..f980815 100644 --- a/helpers/common_helper.php +++ b/helpers/common_helper.php @@ -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(); } } @@ -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; + } +} diff --git a/helpers/nanoid_helper.php b/helpers/nanoid_helper.php index 35fb0d9..6fff73c 100644 --- a/helpers/nanoid_helper.php +++ b/helpers/nanoid_helper.php @@ -11,21 +11,20 @@ /** * Function randomNanoId * - * @param int $size + * @param $size + * @param $prefix * * @return string * @author : 713uk13m * @copyright: 713uk13m - * @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); } } diff --git a/helpers/uuid_helper.php b/helpers/uuid_helper.php index 2f6bbda..5884deb 100644 --- a/helpers/uuid_helper.php +++ b/helpers/uuid_helper.php @@ -58,7 +58,6 @@ function generate_uuid_v3($namespace, $name) substr($hash, 20, 12)); } } - if (!function_exists('generate_uuid_v4')) { /** * Function generate_uuid_v4 diff --git a/src/BaseHelper.php b/src/BaseHelper.php index 04bbd58..607a91a 100644 --- a/src/BaseHelper.php +++ b/src/BaseHelper.php @@ -19,8 +19,8 @@ */ class BaseHelper { - const VERSION = '1.3.2'; - 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';