-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from nguyenanhung/develop
Release version 1.6.2
- Loading branch information
Showing
53 changed files
with
2,699 additions
and
908 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* Project codeigniter-basic-helper | ||
* Created by PhpStorm | ||
|
@@ -7,7 +8,7 @@ | |
* Date: 09/11/2021 | ||
* Time: 08:52 | ||
*/ | ||
if (!function_exists('generateAlphaId')) { | ||
if ( ! function_exists('generateAlphaId')) { | ||
/** | ||
* Translates a number to a short alphanumeric version | ||
* | ||
|
@@ -50,10 +51,10 @@ | |
* but I haven't really dugg into this. If you have more info on those | ||
* matters feel free to leave a comment. | ||
* | ||
* @param mixed $in String or long input to translate | ||
* @param bool $to_num Reverses translation when true | ||
* @param mixed $pad_up Number or boolean padds the result up to a specified length | ||
* @param mixed $passKey Supplying a password makes it harder to calculate the original ID | ||
* @param mixed $in String or long input to translate | ||
* @param bool $to_num Reverses translation when true | ||
* @param mixed $pad_up Number or boolean padds the result up to a specified length | ||
* @param mixed $passKey Supplying a password makes it harder to calculate the original ID | ||
* | ||
* @return string string or long | ||
* @author Kevin van Zonneveld <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* Project codeigniter-basic-helper | ||
* Created by PhpStorm | ||
|
@@ -7,11 +8,11 @@ | |
* Date: 08/07/2021 | ||
* Time: 01:12 | ||
*/ | ||
if (!function_exists('arrayToObject')) { | ||
if ( ! function_exists('arrayToObject')) { | ||
/** | ||
* Function arrayToObject | ||
* | ||
* @param array|mixed $array | ||
* @param array|mixed $array | ||
* | ||
* @return array|false|\stdClass | ||
* @author : 713uk13m <[email protected]> | ||
|
@@ -20,14 +21,14 @@ | |
*/ | ||
function arrayToObject($array = array()) | ||
{ | ||
if (!is_array($array)) { | ||
if ( ! is_array($array)) { | ||
return $array; | ||
} | ||
$object = new stdClass(); | ||
$countArray = count($array); | ||
if ($countArray > 0) { | ||
foreach ($array as $name => $value) { | ||
if (!empty($name)) { | ||
if ( ! empty($name)) { | ||
$object->$name = arrayToObject($value); | ||
} | ||
} | ||
|
@@ -36,13 +37,13 @@ function arrayToObject($array = array()) | |
return false; | ||
} | ||
} | ||
if (!function_exists('arrayToXml')) { | ||
if ( ! function_exists('arrayToXml')) { | ||
/** | ||
* Function arrayToXml | ||
* | ||
* @param array|mixed $array | ||
* @param string $namespace | ||
* @param mixed $file_output | ||
* @param array|mixed $array | ||
* @param string $namespace | ||
* @param mixed $file_output | ||
* | ||
* @return bool|string|null | ||
* @throws \Exception | ||
|
@@ -53,15 +54,18 @@ function arrayToObject($array = array()) | |
function arrayToXml($array = array(), $namespace = '', $file_output = null) | ||
{ | ||
if (class_exists('SimpleXMLElement')) { | ||
$xml_object = new SimpleXMLElement("<?xml version=\"1.0\"?><" . $namespace . "></" . $namespace . ">"); // creating object of SimpleXMLElement | ||
$xml_object = new SimpleXMLElement( | ||
"<?xml version=\"1.0\"?><" . $namespace . "></" . $namespace . ">" | ||
); // creating object of SimpleXMLElement | ||
convertArrayToXml($array, $xml_object); // function call to convert array to xml | ||
$xml_file = $file_output !== null ? $xml_object->asXML($file_output) : $xml_object->asXML(); // saving generated xml file | ||
return !empty($xml_file) ? $xml_file : null; | ||
$xml_file = $file_output !== null ? $xml_object->asXML($file_output) : $xml_object->asXML( | ||
); // saving generated xml file | ||
return ! empty($xml_file) ? $xml_file : null; | ||
} | ||
return null; | ||
} | ||
} | ||
if (!function_exists('convertArrayToXml')) { | ||
if ( ! function_exists('convertArrayToXml')) { | ||
/** | ||
* Function convertArrayToXml | ||
* | ||
|
@@ -76,7 +80,7 @@ function convertArrayToXml($array, &$SimpleXMLElement) | |
{ | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
if (!is_numeric($key)) { | ||
if ( ! is_numeric($key)) { | ||
$subNode = $SimpleXMLElement->addChild((string)$key); | ||
} else { | ||
$subNode = $SimpleXMLElement->addChild("item" . $key); | ||
|
@@ -88,7 +92,7 @@ function convertArrayToXml($array, &$SimpleXMLElement) | |
} | ||
} | ||
} | ||
if (!function_exists('removeArrayElementWithValue')) { | ||
if ( ! function_exists('removeArrayElementWithValue')) { | ||
/** | ||
* Function removeArrayElementWithValue - Loại bỏ 1 giá trị trong array theo key và value | ||
* | ||
|
@@ -111,7 +115,7 @@ function removeArrayElementWithValue($array, $key, $value) | |
return $array; | ||
} | ||
} | ||
if (!function_exists('arrayRecursiveDiff')) { | ||
if ( ! function_exists('arrayRecursiveDiff')) { | ||
/** | ||
* Function arrayRecursiveDiff - Diff 2 array bằng đệ quy | ||
* | ||
|
@@ -143,7 +147,7 @@ function arrayRecursiveDiff($aArray1, $aArray2) | |
return $aReturn; | ||
} | ||
} | ||
if (!function_exists('arrayIsAssoc')) { | ||
if ( ! function_exists('arrayIsAssoc')) { | ||
/** | ||
* Function arrayIsAssoc - Detects if the given value is an associative array. | ||
* | ||
|
@@ -167,21 +171,21 @@ function arrayRecursiveDiff($aArray1, $aArray2) | |
* // bool(true) | ||
* ``` | ||
* | ||
* @param array $array | ||
* @param array $array | ||
* Any type of array. | ||
* | ||
* @return bool | ||
* True if the array is associative, false otherwise. | ||
*/ | ||
function arrayIsAssoc($array) | ||
{ | ||
if (!is_array($array) || $array === array()) { | ||
if ( ! is_array($array) || $array === array()) { | ||
return false; | ||
} | ||
return array_keys($array) !== range(0, count($array) - 1); | ||
} | ||
} | ||
if (!function_exists('arrayFirstElement')) { | ||
if ( ! function_exists('arrayFirstElement')) { | ||
/** | ||
* Function arrayFirstElement - Returns the first element of an array. | ||
* | ||
|
@@ -206,7 +210,7 @@ function arrayIsAssoc($array) | |
* // bar | ||
* ``` | ||
* | ||
* @param array $array | ||
* @param array $array | ||
* The concerned array. | ||
* | ||
* @return mixed | ||
|
@@ -218,7 +222,7 @@ function arrayFirstElement($array) | |
return $array[array_keys($array)[0]]; | ||
} | ||
} | ||
if (!function_exists('arrayLastElement')) { | ||
if ( ! function_exists('arrayLastElement')) { | ||
/** | ||
* Function arrayLastElement - Returns the last element of an array. | ||
* | ||
|
@@ -243,7 +247,7 @@ function arrayFirstElement($array) | |
* // qux | ||
* ``` | ||
* | ||
* @param array $array | ||
* @param array $array | ||
* The concerned array. | ||
* | ||
* @return mixed | ||
|
@@ -254,7 +258,7 @@ function arrayLastElement($array) | |
return $array[array_keys($array)[count($array) - 1]]; | ||
} | ||
} | ||
if (!function_exists('arrayGetElement')) { | ||
if ( ! function_exists('arrayGetElement')) { | ||
/** | ||
* Function arrayGetElement - Gets a value in an array by dot notation for the keys. | ||
* | ||
|
@@ -281,9 +285,9 @@ function arrayLastElement($array) | |
* // foobar | ||
* ``` | ||
* | ||
* @param string $key | ||
* @param string $key | ||
* The key by dot notation. | ||
* @param array $array | ||
* @param array $array | ||
* The array to search in. | ||
* | ||
* @return mixed | ||
|
@@ -295,7 +299,7 @@ function arrayGetElement($key, $array) | |
$keys = explode('.', $key); | ||
while (count($keys) >= 1) { | ||
$k = array_shift($keys); | ||
if (!isset($array[$k])) { | ||
if ( ! isset($array[$k])) { | ||
return null; | ||
} | ||
if (count($keys) === 0) { | ||
|
@@ -307,7 +311,7 @@ function arrayGetElement($key, $array) | |
return null; | ||
} | ||
} | ||
if (!function_exists('arraySetElement')) { | ||
if ( ! function_exists('arraySetElement')) { | ||
/** | ||
* Function arraySetElement - Sets a value in an array using the dot notation. | ||
* | ||
|
@@ -359,27 +363,27 @@ function arrayGetElement($key, $array) | |
* // ) | ||
* ``` | ||
* | ||
* @param string $key | ||
* @param string $key | ||
* The key to set using dot notation. | ||
* @param mixed $value | ||
* @param mixed $value | ||
* The value to set on the specified key. | ||
* @param array $array | ||
* @param array $array | ||
* The concerned array. | ||
* | ||
* @return bool | ||
* True if the new value was successfully set, false otherwise. | ||
*/ | ||
function arraySetElement($key, $value, &$array) | ||
{ | ||
if (is_string($key) && !empty($key)) { | ||
if (is_string($key) && ! empty($key)) { | ||
$keys = explode('.', $key); | ||
$arrTmp = &$array; | ||
while (count($keys) >= 1) { | ||
$k = array_shift($keys); | ||
if (!is_array($arrTmp)) { | ||
if ( ! is_array($arrTmp)) { | ||
$arrTmp = array(); | ||
} | ||
if (!isset($arrTmp[$k])) { | ||
if ( ! isset($arrTmp[$k])) { | ||
$arrTmp[$k] = array(); | ||
} | ||
if (count($keys) === 0) { | ||
|
@@ -392,7 +396,7 @@ function arraySetElement($key, $value, &$array) | |
return false; | ||
} | ||
} | ||
if (!function_exists('to_array')) { | ||
if ( ! function_exists('to_array')) { | ||
/** | ||
* Function to_array - Converts a string or an object to an array. | ||
* | ||
|
@@ -429,7 +433,7 @@ function arraySetElement($key, $value, &$array) | |
* // ) | ||
* ``` | ||
* | ||
* @param string|object $var | ||
* @param string|object $var | ||
* String or object. | ||
* | ||
* @return array|null | ||
|
@@ -447,11 +451,11 @@ function to_array($var) | |
return null; | ||
} | ||
} | ||
if (!function_exists('arrayToAttributes')) { | ||
if ( ! function_exists('arrayToAttributes')) { | ||
/** | ||
* Takes an array of attributes and turns it into a string for an html tag | ||
* | ||
* @param array $attr | ||
* @param array $attr | ||
* | ||
* @return string | ||
*/ | ||
|
Oops, something went wrong.