Overview

Namespaces

  • GAubry
    • ErrorHandler
    • Helpers
    • Logger
    • Shell
  • Himedia
    • Padocc
      • DB
      • Minifier
      • Numbering
      • Properties
      • Task
        • Base
        • Extended
  • None
  • Psr
    • Log

Classes

  • Debug
  • Helpers
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Class Helpers

Some helpers used in several personal packages.

Namespace: GAubry\Helpers
Copyright: 2013 Geoffroy Aubry <geoffroy.aubry@free.fr>
License: http://www.gnu.org/licenses/lgpl.html
SuppressWarnings(TooManyMethods): Copyright (c) 2013 Geoffroy Aubry <geoffroy.aubry@free.fr> Licensed under the GNU Lesser General Public License v3 (LGPL version 3).
Located at helpers/src/GAubry/Helpers/Helpers.php
Methods summary
private
# __construct( )

CodeCoverageIgnore

public static array
# flattenArray( array $aArray )

Flatten a multidimensional array (keys are ignored).

Flatten a multidimensional array (keys are ignored).

Parameters

$aArray
array
$aArray

Returns

array
a one dimensional array.

See

http://stackoverflow.com/a/1320156/1813519
public static string
# utf8Encode( string $str )

Returns the UTF-8 translation of the specified string, only if not already in UTF-8.

Returns the UTF-8 translation of the specified string, only if not already in UTF-8.

Parameters

$str
string
$s

Returns

string
the UTF-8 translation of the specified string, only if not already in UTF-8.
public static array
# exec( string $sCmd, string $sOutputPath = '', string $sErrorPath = '', boolean $bAppend = false )

Executes the given shell command and returns an array filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. On shell error (exit code <> 0), throws a \RuntimeException with error message..

Executes the given shell command and returns an array filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. On shell error (exit code <> 0), throws a \RuntimeException with error message..

Parameters

$sCmd
string
$sCmd shell command
$sOutputPath
string
$sOutputPath optional redirection of standard output
$sErrorPath
string
$sErrorPath optional redirection of standard error
$bAppend
boolean
$bAppend true to append to specified files

Returns

array
array filled with every line of output from the command

Throws

RuntimeException
if shell error
public static string
# stripBashColors( string $sMsg )

Remove all Bash color sequences from the specified string.

Remove all Bash color sequences from the specified string.

Parameters

$sMsg
string
$sMsg

Returns

string
specified string without any Bash color sequence.
public static string
# round( float $fValue, integer $iPrecision = 0 )

Rounds specified value with precision $iPrecision as native round() function, but keep trailing zeros.

Rounds specified value with precision $iPrecision as native round() function, but keep trailing zeros.

Parameters

$fValue
float
$fValue value to round
$iPrecision
integer
$iPrecision the optional number of decimal digits to round to (can also be negative)

Returns

string
public static string
# ucwordWithDelimiters( string $sString, array $aDelimiters = array() )

Returns a string with the first character of each word in specified string capitalized, if that character is alphabetic. Additionally, each character that is immediately after one of $aDelimiters will be capitalized too.

Returns a string with the first character of each word in specified string capitalized, if that character is alphabetic. Additionally, each character that is immediately after one of $aDelimiters will be capitalized too.

Parameters

$sString
string
$sString
$aDelimiters
array
$aDelimiters

Returns

string
public static array
# intToMultiple( integer $iValue, boolean $bBinaryPrefix = false )

Returns specified value in the most appropriate unit, with that unit. If $bBinaryPrefix is FALSE then use SI units (i.e. k, M, G, T), else use IED units (i.e. Ki, Mi, Gi, Ti).

Returns specified value in the most appropriate unit, with that unit. If $bBinaryPrefix is FALSE then use SI units (i.e. k, M, G, T), else use IED units (i.e. Ki, Mi, Gi, Ti).

Parameters

$iValue
integer
$iValue
$bBinaryPrefix
boolean
$bBinaryPrefix

Returns

array
a pair constituted by specified value in the most appropriate unit and that unit

See

http://en.wikipedia.org/wiki/Binary_prefix
public static string
# numberFormat( float $fNumber, string $sDecPoint = '.', string $sThousandsSep = ',', integer $iDecimals = null )

Format a number with grouped thousands. It is an extended version of number_format() that allows do not specify $decimals.

Format a number with grouped thousands. It is an extended version of number_format() that allows do not specify $decimals.

Parameters

$fNumber
float
$fNumber The number being formatted.
$sDecPoint
string
$sDecPoint Sets the separator for the decimal point.
$sThousandsSep
string
$sThousandsSep Sets the thousands separator. Only the first character of $thousands_sep is used.
$iDecimals
integer
$iDecimals Sets the number of decimal points.

Returns

string
A formatted version of $number.
public static string
# strPutCSV( array $aInput, string $sDelimiter = ',', string $sEnclosure = '"' )

Formats a line passed as a fields array as CSV and return it, without the trailing newline. Inspiration: http://www.php.net/manual/en/function.str-getcsv.php#88773

Formats a line passed as a fields array as CSV and return it, without the trailing newline. Inspiration: http://www.php.net/manual/en/function.str-getcsv.php#88773

Parameters

$aInput
array
$aInput
$sDelimiter
string
$sDelimiter
$sEnclosure
string
$sEnclosure

Returns

string
specified array converted into CSV format string
public static array
# arrayMergeRecursiveDistinct( array $aArray1, array $aArray2 )

array_merge_recursive() does indeed merge arrays, but it converts values with duplicate keys to arrays rather than overwriting the value in the first array with the duplicate value in the second array, as array_merge does. I.e., with array_merge_recursive(), this happens (documented behavior):

array_merge_recursive() does indeed merge arrays, but it converts values with duplicate keys to arrays rather than overwriting the value in the first array with the duplicate value in the second array, as array_merge does. I.e., with array_merge_recursive(), this happens (documented behavior):

array_merge_recursive(array('key' => 'org value'), array('key' => 'new value')); ⇒ array('key' => array('org value', 'new value'));

arrayMergeRecursiveDistinct() does not change the datatypes of the values in the arrays. Matching keys' values in the second array overwrite those in the first array, as is the case with array_merge, i.e.:

arrayMergeRecursiveDistinct(array('key' => 'org value'), array('key' => 'new value')); ⇒ array('key' => array('new value'));

EVO on indexed arrays: Before: arrayMergeRecursiveDistinct(array('a', 'b'), array('c')) ⇒ array('c', 'b') Now: ⇒ array('c')

Parameters

$aArray1
array
$aArray1
$aArray2
array
$aArray2

Returns

array
An array of values resulted from strictly merging the arguments together.

Author

Daniel <daniel (at) danielsmedegaardbuus (dot) dk>
Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com>
Geoffroy Aubry

See

http://fr2.php.net/manual/en/function.array-merge-recursive.php#89684
public static boolean
# isAssociativeArray( array $aArray )

Returns TRUE iff the specified array is associative. If the specified array is empty, then return FALSE.

Returns TRUE iff the specified array is associative. If the specified array is empty, then return FALSE.

http://stackoverflow.com/questions/173400/php-arrays-a-good-way-to-check-if-an-array-is-associative-or-sequential

Parameters

$aArray
array
$aArray

Returns

boolean
true ssi iff the specified array is associative
Platform for Automatized Deployments with pOwerful Concise Configuration API documentation generated by ApiGen 2.8.0