PHP 클래스 lithium\util\Set

- '/User/id': Similar to the classic {n}.User.id. - '/User[2]/name': Selects the name of the second User. - '/User[id>2]': Selects all Users with an id > 2. - '/User[id>2][<5]': Selects all Users with an id > 2 but < 5. - '/Post/Comment[author_name=John]/../name': Selects the name of all posts that have at least one comment written by John. - '/Posts[name]': Selects all Posts that have a 'name' key. - '/Comment/.[1]': Selects the contents of the first comment. - '/Comment/.[:last]': Selects the last comment. - '/Comment/.[:first]': Selects the first comment. - '/Comment[text=/lithium/i]': Selects the all comments that have a text matching the regex /lithium/i. - '/Comment/@*': Selects all key names of all comments.
파일 보기 프로젝트 열기: unionofrad/lithium 1 사용 예제들

공개 메소드들

메소드 설명
append ( array $array, array $array2 ) : array Add the keys/values in $array2 that are not found in $array onto the end of $array.
check ( mixed $data, mixed $path = null ) : boolean Checks if a particular path is set in an array. Tests by key name, or dot-delimited key name, i.e.:
combine ( array $data, mixed $path1 = null, mixed $path2 = null, string $groupPath = null ) : array Creates an associative array using a $path1 as the path to build its keys, and optionally $path2 as path to get the values. If $path2 is not specified, all values will be initialized to null (useful for Set::merge()). You can optionally group the values by what is obtained when following the path specified in $groupPath.
contains ( array $array1, array $array2 ) : boolean Determines if the array elements in $array2 are wholly contained within $array1. Works recursively.
depth ( array $data, array $options = [] ) : 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.
diff ( array $val1, array $val2 ) : array Computes the difference between two arrays.
expand ( array $data, array $options = [] ) : array Accepts a one-dimensional array where the keys are separated by a delimiter.
extract ( array $data, string $path = null, array $options = [] ) : array Implements partial support for XPath 2.0.
flatten ( array $data, array $options = [] ) : array Collapses a multi-dimensional array into a single dimension, using a delimited array path for each array element's key, i.e. array(array('Foo' => array('Bar' => 'Far'))) becomes array('0.Foo.Bar' => 'Far').
format ( array $data, string $format, array $keys ) : array Returns a series of values extracted from an array, formatted in a format string.
insert ( mixed $list, mixed $path, array $data = [] ) : array Inserts $data into an array as defined by $path.
isNumeric ( array $array = null ) : mixed Checks to see if all the values in the array are numeric.
matches ( array $data, mixed $conditions, integer $i = null, integer $length = null ) : boolean This function can be used to see if a single item or a given XPath match certain conditions.
merge ( array $array1, array $array2 ) : array This method can be thought of as a hybrid between PHP's array_merge() and array_merge_recursive(). The difference to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge()) but does not do if for keys containing strings (unlike array_merge_recursive()). Please note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
normalize ( string | array $list, boolean $assoc = true, string $sep = ',', boolean $trim = true ) : array Normalizes a string or array list.
remove ( mixed $list, mixed $path = null ) : array Removes an element from an array as defined by $path.
slice ( array $data, array | string $keys ) : array Slices an array into two, separating them determined by an array of keys.
sort ( array $data, string $path, string $dir = 'asc' ) : array Sorts an array by any value, determined by a Set-compatible path.

메소드 상세

append() 공개 정적인 메소드

Add the keys/values in $array2 that are not found in $array onto the end of $array.
public static append ( array $array, array $array2 ) : array
$array array Original array.
$array2 array Second array to add onto the original.
리턴 array An array containing all the keys of the second array not already present in the first.

check() 공개 정적인 메소드

embed:lithium\tests\cases\util\SetTest::testCheck(1-4)
public static check ( mixed $data, mixed $path = null ) : boolean
$data mixed Data to check on.
$path mixed A dot-delimited string.
리턴 boolean `true` if path is found, `false` otherwise.

combine() 공개 정적인 메소드

Creates an associative array using a $path1 as the path to build its keys, and optionally $path2 as path to get the values. If $path2 is not specified, all values will be initialized to null (useful for Set::merge()). You can optionally group the values by what is obtained when following the path specified in $groupPath.
public static combine ( array $data, mixed $path1 = null, mixed $path2 = null, string $groupPath = null ) : array
$data array Array from where to extract keys and values.
$path1 mixed As an array, or as a dot-delimited string.
$path2 mixed As an array, or as a dot-delimited string.
$groupPath string As an array, or as a dot-delimited string.
리턴 array Combined array.

contains() 공개 정적인 메소드

Determines if the array elements in $array2 are wholly contained within $array1. Works recursively.
public static contains ( array $array1, array $array2 ) : boolean
$array1 array First value.
$array2 array Second value.
리턴 boolean Returns `true` if `$array1` wholly contains the keys and values of `$array2`, otherwise, returns `false`. Returns `false` if either array is empty.

depth() 공개 정적인 메소드

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 depth ( array $data, array $options = [] ) : integer
$data array Array to count dimensions on.
$options array
리턴 integer The number of dimensions in `$array`.

diff() 공개 정적인 메소드

Computes the difference between two arrays.
public static diff ( array $val1, array $val2 ) : array
$val1 array First value.
$val2 array Second value.
리턴 array Computed difference.

expand() 공개 정적인 메소드

Accepts a one-dimensional array where the keys are separated by a delimiter.
public static expand ( array $data, array $options = [] ) : array
$data array The one-dimensional array to expand.
$options array The options used when expanding the array: - `'separator'` _string_: The delimiter to use when separating keys. Defaults to `'.'`.
리턴 array Returns a multi-dimensional array expanded from a one dimensional dot-separated array.

extract() 공개 정적인 메소드

Implements partial support for XPath 2.0.
public static extract ( array $data, string $path = null, array $options = [] ) : array
$data array An array of data to extract from.
$path string An absolute XPath 2.0 path. Only absolute paths starting with a single slash are supported right now. Implemented selectors: - `'/User/id'`: Similar to the classic {n}.User.id. - `'/User[2]/name'`: Selects the name of the second User. - `'/User[id>2]'`: Selects all Users with an id > 2. - `'/User[id>2][<5]'`: Selects all Users with an id > 2 but < 5. - `'/Post/Comment[author_name=John]/../name'`: Selects the name of all posts that have at least one comment written by John. - `'/Posts[name]'`: Selects all Posts that have a `'name'` key. - `'/Comment/.[1]'`: Selects the contents of the first comment. - `'/Comment/.[:last]'`: Selects the last comment. - `'/Comment/.[:first]'`: Selects the first comment. - `'/Comment[text=/lithium/i]`': Selects the all comments that have a text matching the regex `/lithium/i`. - `'/Comment/@*'`: Selects all key names of all comments.
$options array Currently only supports `'flatten'` which can be disabled for higher XPath-ness.
리턴 array An array of matched items.

flatten() 공개 정적인 메소드

Collapses a multi-dimensional array into a single dimension, using a delimited array path for each array element's key, i.e. array(array('Foo' => array('Bar' => 'Far'))) becomes array('0.Foo.Bar' => 'Far').
public static flatten ( array $data, array $options = [] ) : array
$data array array to flatten
$options array Available options are: - `'separator'`: String to separate array keys in path (defaults to `'.'`). - `'path'`: Starting point (defaults to null).
리턴 array

format() 공개 정적인 메소드

Returns a series of values extracted from an array, formatted in a format string.
public static format ( array $data, string $format, array $keys ) : array
$data array Source array from which to extract the data.
$format string Format string into which values will be inserted using `sprintf()`.
$keys array An array containing one or more `Set::extract()`-style key paths.
리턴 array An array of strings extracted from `$keys` and formatted with `$format`.

insert() 공개 정적인 메소드

Inserts $data into an array as defined by $path.
public static insert ( mixed $list, mixed $path, array $data = [] ) : array
$list mixed Where to insert into.
$path mixed A dot-delimited string.
$data array Data to insert.
리턴 array

isNumeric() 공개 정적인 메소드

Checks to see if all the values in the array are numeric.
public static isNumeric ( array $array = null ) : mixed
$array array The array to check. If null, the value of the current Set object.
리턴 mixed `true` if values are numeric, `false` if not and `null` if the array to check is empty.

matches() 공개 정적인 메소드

This function can be used to see if a single item or a given XPath match certain conditions.
public static matches ( array $data, mixed $conditions, integer $i = null, integer $length = null ) : boolean
$data array An array of data to execute the match on.
$conditions mixed An array of condition strings or an XPath expression.
$i integer Optional: The 'nth'-number of the item being matched.
$length integer
리턴 boolean

merge() 공개 정적인 메소드

This method can be thought of as a hybrid between PHP's array_merge() and array_merge_recursive(). The difference to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge()) but does not do if for keys containing strings (unlike array_merge_recursive()). Please note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
public static merge ( array $array1, array $array2 ) : array
$array1 array The base array.
$array2 array The array to be merged on top of the base array.
리턴 array Merged array of all passed params.

normalize() 공개 정적인 메소드

Set::normalize('foo,bar'); // returns array('foo' => null, 'bar' => null); Set::normalize(array('foo', 'bar' => 'baz'); // returns array('foo' => null, 'bar' => 'baz');
public static normalize ( string | array $list, boolean $assoc = true, string $sep = ',', boolean $trim = true ) : array
$list string | array List to normalize.
$assoc boolean If `true`, `$list` will be converted to an associative array.
$sep string If `$list` is a string, it will be split into an array with `$sep`.
$trim boolean If `true`, separated strings will be trimmed.
리턴 array

remove() 공개 정적인 메소드

Removes an element from an array as defined by $path.
public static remove ( mixed $list, mixed $path = null ) : array
$list mixed From where to remove.
$path mixed A dot-delimited string.
리턴 array Array with `$path` removed from its value.

slice() 공개 정적인 메소드

Usage examples: embed:lithium\tests\cases\util\SetTest::testSetSlice(1-4)
public static slice ( array $data, array | string $keys ) : array
$data array
$keys array | string An array of keys or a single key as string
리턴 array An array containing both arrays, having the array with requested keys first and the remainder as second element

sort() 공개 정적인 메소드

Sorts an array by any value, determined by a Set-compatible path.
public static sort ( array $data, string $path, string $dir = 'asc' ) : array
$data array
$path string A `Set`-compatible path to the array value.
$dir string Either `'asc'` (the default) or `'desc'`.
리턴 array