Skip to content

Commit

Permalink
Release version 3.0.8.9
Browse files Browse the repository at this point in the history
  • Loading branch information
hungnguyenhp committed Feb 3, 2023
1 parent a22d98c commit f56348f
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 346 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
"ext-mbstring": "*",
"nguyenanhung/array-helper": "^2.0 || ^1.0",
"nguyenanhung/base64-php-helper": "^2.0 || ^1.0",
"nguyenanhung/bool-type-helper": "^2.0 || ^1.0",
"nguyenanhung/bbcode-helper": "^2.0 || ^1.0",
"nguyenanhung/date-helper": "^2.0 || ^1.0",
"nguyenanhung/escape-helper": "^2.0 || ^1.0",
"nguyenanhung/email-helper": "^2.0 || ^1.0",
"nguyenanhung/encryption-helper": "^2.0 || ^1.0",
"nguyenanhung/filesystem-helper": "^2.0 || ^1.0",
"nguyenanhung/filtered-helper": "^2.0 || ^1.0",
"nguyenanhung/hashids-helper": "^2.0 || ^1.0",
"nguyenanhung/html-helper": "^2.0 || ^1.0",
"nguyenanhung/http-download-helper": "^2.0 || ^1.0",
"nguyenanhung/ip-helper": "^2.0 || ^1.0",
"nguyenanhung/json-helper": "^2.0 || ^1.0",
"nguyenanhung/jwt-helper": "^2.0 || ^1.0",
"nguyenanhung/math-helper": "^2.0 || ^1.0",
"nguyenanhung/mobile-helper": "^2.0 || ^1.0",
"nguyenanhung/nanoid-helper": "^2.0 || ^1.0",
Expand Down
6 changes: 0 additions & 6 deletions helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ function isEmpty($input = ''): bool
return (new nguyenanhung\Classes\Helper\Common())->isEmpty($input);
}
}
if (!function_exists('isEmail')) {
function isEmail($mail = ''): bool
{
return \nguyenanhung\Classes\Helper\Email::validateEmail($mail);
}
}
if (!function_exists('developer_fullname_copyright')) {
function developer_name_copyright(): string
{
Expand Down
189 changes: 2 additions & 187 deletions src/BoolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

namespace nguyenanhung\Classes\Helper;

use InvalidArgumentException;
use BadMethodCallException;
use nguyenanhung\Libraries\BoolType\BoolType as BaseBoolType;

if (!class_exists('nguyenanhung\Classes\Helper\BoolType')) {
/**
Expand All @@ -20,192 +19,8 @@
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*/
class BoolType
class BoolType extends BaseBoolType
{
/**
* Returns $bool value in the string $format
*
* I'll return a bool value as a true-false, yes-no, or on-off string.
*
* For example:
*
* BoolType::boolToString(true); // returns (string) 'true'
* BoolType::boolToString(true, 'yes-no'); // returns (string) 'true'
* BoolType::boolToString(false, 'on-off'); // returns (string) 'off'
*
* @since 0.1.0
*
* @param bool $bool the boolean value to convert
* @param string $format the string format to convert to (possible values are
* 't[/-]f', true[/-]false', 'y[/-]n', 'yes[/-]no', 'o[/-o]', and 'on[/-]off')
* (case-insensitive) (optional; if omitted, defaults to 'true-false')
*
* @return string the string value
*
* @throws \BadMethodCallException if $bool is null
* @throws \InvalidArgumentException if $bool is not a (bool) value
* @throws \InvalidArgumentException if $format is not a string
* @throws \InvalidArgumentException if $format is not a valid format
*/
public static function boolToString($bool, $format = 'true-false'): string
{
$string = false;

// if $bool and format are not null
if ($bool !== null && $format !== null) {
// if $bool is actually a bool
if (is_bool($bool)) {
// if $format is a string
if (is_string($format)) {
// switch on the lower-case $format
switch (strtolower($format)) {

case 'oo':
case 'o/o':
case 'o-o':
case 'onoff':
case 'on/off':
case 'on-off':
$string = $bool ? 'on' : 'off';
break;

case 'tf':
case 't/f':
case 't-f':
case 'truefalse':
case 'true/false':
case 'true-false':
$string = $bool ? 'true' : 'false';
break;

case 'yn':
case 'y/n':
case 'y-n':
case 'yesno':
case 'yes/no':
case 'yes-no':
$string = $bool ? 'yes' : 'no';
break;

default:
throw new InvalidArgumentException(__METHOD__ . "() expects parameter two, format, to be one of the following: " . "'t[/-]f', 'true[/-]false', 'y[/-]s', 'yes[/-]no', 'o[/-]o', or " . "'on[/-]off', '$format' given");
}
} else {
throw new InvalidArgumentException(__METHOD__ . "() expects parameter two, format, to be a string");
}
} else {
throw new InvalidArgumentException(__METHOD__ . "() expects parameter one, bool, to be a bool value given");
}
} else {
throw new BadMethodCallException(__METHOD__ . "() expects one or two parameters, a bool value and a string format");
}

return $string;
}

/**
* Returns the boolean value of $var
*
* PHP's native boolval() function is not available before PHP 5.5, and it does not
* support the strings 'yes', 'no', 'on', or 'off'.
*
* I follow the following rules:
*
* Strings
* The strings "yes", "true", "on", or "1" are considered true, and
* the strings "no", "false", "off", or "0" are considered false
* (case-insensitive). Any other non-empty string is true.
*
* Numbers
* The numbers 0 or 0.0 are considered false. Any other number is
* considered true.
*
* Array
* An empty array is considered false. Any other array (even an
* associative array with no values) is considered true.
*
* Object
* Any object is considered true.
*
* For example...
*
* BoolType::val(""); // returns (bool) false
* BoolType::val(true); // returns (bool) true
* BoolType::val(0); // returns (bool) false
* BoolType::val(0.0); // returns (bool) false
* BoolType::val('0'); // returns (bool) false
* BoolType::val('abc'); // returns (bool) true
* BoolType::val('true'); // returns (bool) true
* BoolType::val('on'); // returns (bool) true
* BoolType::val('yes'); // returns (bool) true
* BoolType::val('off'); // returns (bool) false
* BoolType::val([]); // returns (bool) false
* BoolType::val([1, 2]); // returns (bool) true
* BoolType::val(new StdClass()); // returns (bool) true
*
* @since 0.1.0
*
* @param mixed $var the variable to test
*
* @return bool|null the bool value
*
* @see http://www.php.net/manual/en/function.boolval.php boolval() man page
*/
public static function val($var)
{
$value = null;

// if $var is not empty
// any value considered empty by empty() is considered false
// for example, "0", array(), "", etc
//
if (!empty($var)) {
// if $var is not already a bool type
if (!is_bool($var)) {
// if $var is a string
if (is_string($var)) {
// switch on the string
// the strings '1', 'on', 'yes', and 'true' are considered true
// the strings '0', 'no', 'off', and 'false' are considered false
// any other non-empty string is true
//
switch (strtolower($var)) {

case '1':
case 'on':
case 'yes':
case 'true':
$value = true;
break;

case '0':
case 'no':
case 'off':
case 'false':
$value = false;
break;

default:
$value = !empty($var);
}
} elseif (is_numeric($var)) {
// any non-zero integer or float is considered true
$value = ($var !== 0 && $var !== 0.0);
} elseif (is_object($var)) {
// any object is considered true
$value = true;
} elseif (is_array($var)) {
// any non-empty array is considered true
$value = !empty($var);
}
} else {
$value = $var;
}
} else {
$value = false;
}

return $value;
}
}
}
52 changes: 21 additions & 31 deletions src/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,14 @@ class Common implements ProjectInterface

use Version;

/**
* Function dump
*
* @param $str
*
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 30/12/2022 12:51
*/
public function dump($str)
{
echo "<pre>";
var_dump($str);
echo "</pre>";
return dump($str);
}

/**
* Function dump_die
*
* @param $str
*
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 30/12/2022 13:17
*/
public function dump_die($str)
{
echo "<pre>";
var_dump($str);
echo "</pre>";
die;
dump_die($str);
}

/**
Expand Down Expand Up @@ -220,9 +197,7 @@ public function directoryMap($source_dir, $directory_depth = 0, $hidden = false)
*/
public function newFolder($pathname = '', $mode = 0777): bool
{
$file = new File();

return $file->createNewFolder($pathname, $mode);
return (new File())->createNewFolder($pathname, $mode);
}

/**
Expand All @@ -237,9 +212,7 @@ public function newFolder($pathname = '', $mode = 0777): bool
*/
public function formatSizeUnits($bytes = 0): string
{
$file = new File();

return $file->formatSizeUnits($bytes);
return (new File())->formatSizeUnits($bytes);
}

/**
Expand Down Expand Up @@ -684,6 +657,23 @@ public function highlightPhrase($str = '', $phrase = '', $tag_open = '<mark>', $
return TextProcessor::highlightPhrase($str, $phrase, $tag_open, $tag_close);
}

/**
* Keyword Highlighter
*
* Highlights a keyword within a text string
*
* @param string $str the text string
* @param string $phrase the phrase you'd like to highlight
* @param string $tag_open the opening tag to precede the phrase with
* @param string $tag_close the closing tag to end the phrase with
*
* @return string
*/
public function highlightKeyword($str = '', $phrase = '', $tag_open = '<mark>', $tag_close = '</mark>'): string
{
return TextProcessor::highlightKeyword($str, $phrase, $tag_open, $tag_close);
}

/**
* Function convertStrToEn
*
Expand Down
26 changes: 3 additions & 23 deletions src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace nguyenanhung\Classes\Helper;

use nguyenanhung\Libraries\Email\Email as BaseEmail;

if (!class_exists('nguyenanhung\Classes\Helper\Email')) {
/**
* Class Email
Expand All @@ -18,30 +20,8 @@
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*/
class Email implements ProjectInterface
class Email extends BaseEmail implements ProjectInterface
{
use Version;

/**
* Function validateEmail
*
* @param $email
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 07/28/2021 59:25
*/
public static function validateEmail($email): bool
{
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return true;
}

return false;
}
}
}
Loading

0 comments on commit f56348f

Please sign in to comment.