Skip to content

Commit

Permalink
Merge pull request #50 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Release version 1.6.2
  • Loading branch information
nguyenanhung authored Apr 5, 2024
2 parents c21869b + fd53920 commit 6e4d0cc
Show file tree
Hide file tree
Showing 53 changed files with 2,699 additions and 908 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
name: Testing CodeIgniter Basic Helper by HungNG
on: [ push, pull_request ]
jobs:
build:
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'ubuntu-20.04', 'ubuntu-22.04', 'macos-latest', 'macos-11', 'macos-12' ]
php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 # From https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, curl, json, openssl, iconv, bcmath, xml
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
build:
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'ubuntu-20.04', 'ubuntu-22.04' ]
php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 # From https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, curl, json, openssl, iconv, bcmath, xml
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"nguyenanhung/basic-miscellaneous-helper": "^2.0 || ^1.0"
},
"require-dev": {
"nguyenanhung/my-debug": "^3.0 || ^2.0",
"nguyenanhung/my-debug": "^4.0 || ^3.0 || ^2.0",
"nguyenanhung/nanoid-helper": "^2.0 || ^1.0",
"nguyenanhung/json-helper": "^2.0 || ^1.0",
"nguyenanhung/image": "^3.0 || ^2.0 || ^1.0",
Expand Down
11 changes: 6 additions & 5 deletions helpers/alphaid_helper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Project codeigniter-basic-helper
* Created by PhpStorm
Expand All @@ -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
*
Expand Down Expand Up @@ -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]>
Expand Down
78 changes: 41 additions & 37 deletions helpers/array_helper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Project codeigniter-basic-helper
* Created by PhpStorm
Expand All @@ -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]>
Expand All @@ -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);
}
}
Expand All @@ -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
Expand All @@ -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
*
Expand All @@ -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);
Expand All @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -206,7 +210,7 @@ function arrayIsAssoc($array)
* // bar
* ```
*
* @param array $array
* @param array $array
* The concerned array.
*
* @return mixed
Expand All @@ -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.
*
Expand All @@ -243,7 +247,7 @@ function arrayFirstElement($array)
* // qux
* ```
*
* @param array $array
* @param array $array
* The concerned array.
*
* @return mixed
Expand All @@ -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.
*
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
*
Expand Down Expand Up @@ -429,7 +433,7 @@ function arraySetElement($key, $value, &$array)
* // )
* ```
*
* @param string|object $var
* @param string|object $var
* String or object.
*
* @return array|null
Expand All @@ -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
*/
Expand Down
Loading

0 comments on commit 6e4d0cc

Please sign in to comment.