PHP 클래스 Tools\Utility\Utility

저자: Mark Scherer
파일 보기 프로젝트 열기: dereuromark/cakephp-tools 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_counterStartTime integer

공개 메소드들

메소드 설명
arrayFlatten ( array $array, boolean $preserveKeys = false ) : array Force-flattens an array.
arrayShiftKeys ( array &$array ) : string Similar to array_shift but on the keys of the array like array_shift() only for keys and not values
autoPrefixUrl ( string $url, string | null $prefix = null ) : string Add protocol prefix if necessary (and possible)
calcElapsedTime ( integer $start, integer $end, integer $precision = 8 ) : float Returns microtime as float value (to be subtracted right away)
cleanUrl ( string $url, boolean $headerRedirect = false ) : string Remove unnessary stuff + add http:// for external urls TODO: protocol to lower!
countDim ( array $array, boolean $all = false, integer $count ) : integer Counts the dimensions of an array. If $all is set to false (which is the default) it will only consider the dimension of the first element in the array.
deep ( callable $function, mixed $value ) : array | string Main deep method
expandList ( array $data, string $separator = '.', string | null $undefinedKey = null ) : array Expands the values of an array of strings into a deep array.
fileExists ( string $file, string $pattern = '~^https?://~i' ) : boolean A more robust wrapper around for file_exists() which easily fails to return true for existent remote files.
flattenList ( array $data, string $separator = '.' ) : array Flattens a deep array into an array of strings.
getClientIp ( boolean $safe = true ) : string Get the current IP address.
getHeaderFromUrl ( string $url ) : mixed Parse headers from a specific URL content.
getReferer ( boolean $full = false ) : string Get the current referrer if available.
inArray ( mixed $needle, array $haystack ) : boolean Clean implementation of inArray to avoid false positives.
isValidSaveAll ( array $array ) : boolean On non-transaction db connections it will return a deep array of bools instead of bool.
logicalAnd ( array $array ) : boolean Returns true only if all values are true.
logicalOr ( array $array ) : boolean Returns true if at least one value is true.
microtime ( integer $precision = 8 ) : float Returns microtime as float value (to be subtracted right away)
notEmpty ( mixed $value ) : boolean More sane !empty() method to not false positive '0' (0 as string) as empty.
pregMatch ( string $pattern, string $subject, integer | null $flags = null, integer | null $offset = null ) : array Multibyte analogue of preg_match() function. Only that this returns the result.
pregMatchAll ( string $pattern, string $subject, integer $flags = PREG_SET_ORDER, integer | null $offset = null ) : array Multibyte analogue of preg_match_all() function. Only that this returns the result.
prettyJson ( string $json, string $indString = " " ) : string Returns pretty JSON
returnElapsedTime ( integer $precision = 8, boolean $restartClock = false ) : float
specialcharsDeep ( mixed $value ) : array | string Applies h() recursively
startClock ( ) : void
strSplit ( string $str, integer $length = 1 ) : array Multibyte analogue of str_split() function.
tokenize ( string $data, string $separator = ',', array $options = [] ) : array Tokenizes a string using $separator.
trimDeep ( mixed $value ) : array | string Trim recursively
typeCast ( mixed $value, string $type ) : mixed Convenience function for automatic casting in form methods etc.
urlExists ( string $url ) : boolean file_exists() does not always work with URLs.

보호된 메소드들

메소드 설명
_arrayFlatten ( array $a, array $f = [] ) : array Force-flattens an array and preserves the keys.

메소드 상세

_arrayFlatten() 보호된 정적인 메소드

Careful with this method. It can lose information. The keys will not be changed, thus possibly overwrite each other. TODO: check if it can be replace by Hash::flatten() or Utility::flatten().
protected static _arrayFlatten ( array $a, array $f = [] ) : array
$a array
$f array
리턴 array

arrayFlatten() 공개 정적인 메소드

Careful with this method. It can lose information. The keys will not be changed, thus possibly overwrite each other. TODO: check if it can be replace by Hash::flatten() or Utility::flatten().
public static arrayFlatten ( array $array, boolean $preserveKeys = false ) : array
$array array Array to flatten
$preserveKeys boolean
리턴 array

arrayShiftKeys() 공개 정적인 메소드

Similar to array_shift but on the keys of the array like array_shift() only for keys and not values
public static arrayShiftKeys ( array &$array ) : string
$array array keyValuePairs
리턴 string key

autoPrefixUrl() 공개 정적인 메소드

Add protocol prefix if necessary (and possible)
public static autoPrefixUrl ( string $url, string | null $prefix = null ) : string
$url string
$prefix string | null
리턴 string

calcElapsedTime() 공개 정적인 메소드

Returns microtime as float value (to be subtracted right away)
public static calcElapsedTime ( integer $start, integer $end, integer $precision = 8 ) : float
$start integer
$end integer
$precision integer
리턴 float

cleanUrl() 공개 정적인 메소드

Remove unnessary stuff + add http:// for external urls TODO: protocol to lower!
public static cleanUrl ( string $url, boolean $headerRedirect = false ) : string
$url string
$headerRedirect boolean
리턴 string Cleaned Url

countDim() 공개 정적인 메소드

Counts the dimensions of an array. If $all is set to false (which is the default) it will only consider the dimension of the first element in the array.
public static countDim ( array $array, boolean $all = false, integer $count ) : integer
$array array Array to count dimensions on
$all boolean Set to true to count the dimension considering all elements in array
$count integer Start the dimension count at this number
리턴 integer The number of dimensions in $array

deep() 공개 정적인 메소드

Main deep method
public static deep ( callable $function, mixed $value ) : array | string
$function callable
$value mixed
리턴 array | string

expandList() 공개 정적인 메소드

Opposite of flattenList(). It needs at least a single separator to be present in all values as the key would otherwise be undefined. If data can contain such key-less rows, use $undefinedKey to avoid an exception being thrown. But it will effectivly collide with other values in that same key then. So Some.Deep.Value becomes array('Some' => array('Deep' => array('Value'))).
public static expandList ( array $data, string $separator = '.', string | null $undefinedKey = null ) : array
$data array
$separator string
$undefinedKey string | null
리턴 array

fileExists() 공개 정적인 메소드

Per default it allows http/https images to be looked up via urlExists() for a better result.
public static fileExists ( string $file, string $pattern = '~^https?://~i' ) : boolean
$file string File
$pattern string
리턴 boolean Success

flattenList() 공개 정적인 메소드

Opposite of expandList(). So array('Some' => array('Deep' => array('Value'))) becomes Some.Deep.Value. Note that primarily only string should be used. However, boolean values are casted to int and thus both boolean and integer values also supported.
public static flattenList ( array $data, string $separator = '.' ) : array
$data array
$separator string
리턴 array

getClientIp() 공개 정적인 메소드

Get the current IP address.
public static getClientIp ( boolean $safe = true ) : string
$safe boolean
리턴 string IP address

getHeaderFromUrl() 공개 정적인 메소드

Parse headers from a specific URL content.
public static getHeaderFromUrl ( string $url ) : mixed
$url string
리턴 mixed array of headers or FALSE on failure

getReferer() 공개 정적인 메소드

Get the current referrer if available.
public static getReferer ( boolean $full = false ) : string
$full boolean (defaults to false and leaves the url untouched)
리턴 string referer (local or foreign)

inArray() 공개 정적인 메소드

in_array itself has some PHP flaws regarding cross-type comparison: - in_array('50x', array(40, 50, 60)) would be true! - in_array(50, array('40x', '50x', '60x')) would be true!
public static inArray ( mixed $needle, array $haystack ) : boolean
$needle mixed
$haystack array
리턴 boolean Success

isValidSaveAll() 공개 정적인 메소드

So we need to call this method inside the modified saveAll() method to return the expected single bool there, too.
사용 중단: Not sure this is useful for CakePHP 3.0
public static isValidSaveAll ( array $array ) : boolean
$array array
리턴 boolean

logicalAnd() 공개 정적인 메소드

Returns true only if all values are true.
public static logicalAnd ( array $array ) : boolean
$array array
리턴 boolean Result

logicalOr() 공개 정적인 메소드

Returns true if at least one value is true.
public static logicalOr ( array $array ) : boolean
$array array
리턴 boolean Result

microtime() 공개 정적인 메소드

Returns microtime as float value (to be subtracted right away)
public static microtime ( integer $precision = 8 ) : float
$precision integer
리턴 float

notEmpty() 공개 정적인 메소드

More sane !empty() method to not false positive '0' (0 as string) as empty.
public static notEmpty ( mixed $value ) : boolean
$value mixed
리턴 boolean

pregMatch() 공개 정적인 메소드

By default this works properly with UTF8 strings. Do not forget to use preg_quote() first on strings that could potentially contain unescaped characters. Note that you still need to add the u modifier (for UTF8) to your pattern yourself. Example: /some(.*)pattern/u
public static pregMatch ( string $pattern, string $subject, integer | null $flags = null, integer | null $offset = null ) : array
$pattern string The pattern to use.
$subject string The string to match.
$flags integer | null
$offset integer | null
리턴 array Result

pregMatchAll() 공개 정적인 메소드

By default this works properly with UTF8 strings. Do not forget to use preg_quote() first on strings that could potentially contain unescaped characters. Note that you still need to add the u modifier (for UTF8) to your pattern yourself. Example: /some(.*)pattern/u
public static pregMatchAll ( string $pattern, string $subject, integer $flags = PREG_SET_ORDER, integer | null $offset = null ) : array
$pattern string The pattern to use.
$subject string The string to match.
$flags integer
$offset integer | null
리턴 array Result

prettyJson() 공개 정적인 메소드

Returns pretty JSON
사용 중단: Now there is a JSON_PRETTY_PRINT option available on json_encode()
public static prettyJson ( string $json, string $indString = " " ) : string
$json string The original JSON string
$indString string The string to indent with
리턴 string

returnElapsedTime() 공개 정적인 메소드

public static returnElapsedTime ( integer $precision = 8, boolean $restartClock = false ) : float
$precision integer
$restartClock boolean
리턴 float

specialcharsDeep() 공개 정적인 메소드

Applies h() recursively
public static specialcharsDeep ( mixed $value ) : array | string
$value mixed
리턴 array | string

startClock() 공개 정적인 메소드

public static startClock ( ) : void
리턴 void

strSplit() 공개 정적인 메소드

By default this works properly with UTF8 strings.
public static strSplit ( string $str, integer $length = 1 ) : array
$str string
$length integer
리턴 array Result

tokenize() 공개 정적인 메소드

Options - clean: true/false (defaults to true and removes empty tokens and whitespace)
public static tokenize ( string $data, string $separator = ',', array $options = [] ) : array
$data string The data to tokenize
$separator string The token to split the data on.
$options array
리턴 array

trimDeep() 공개 정적인 메소드

Trim recursively
public static trimDeep ( mixed $value ) : array | string
$value mixed
리턴 array | string

typeCast() 공개 정적인 메소드

Convenience function for automatic casting in form methods etc.
public static typeCast ( mixed $value, string $type ) : mixed
$value mixed
$type string
리턴 mixed Safe value for DB query, or NULL if type was not a valid one

urlExists() 공개 정적인 메소드

So if you check on strpos(http) === 0 you can use this to check for URLs instead.
public static urlExists ( string $url ) : boolean
$url string Absolute URL
리턴 boolean Success

프로퍼티 상세

$_counterStartTime 보호되어 있는 정적으로 프로퍼티

protected static int $_counterStartTime
리턴 integer