Set Class Reference

Inheritance diagram for Set:

Object

List of all members.


Public Member Functions

 check ($data, $path=null)
 combine ($data, $path1=null, $path2=null, $groupPath=null)
 contains ($val1, $val2=null)
 countDim ($array=null, $all=false, $count=0)
 diff ($val1, $val2=null)
 enum ($select, $list=null)
 extract ($data, $path=null)
 filter ($var, $isArray=false)
 format ($data, $format, $keys)
get ()
 insert ($list, $path, $data=null)
 isEqual ($val1, $val2=null)
 map ($class= 'stdClass', $tmp= 'stdClass')
 merge ($arr1, $arr2=null)
 normalize ($list, $assoc=true, $sep= ',', $trim=true)
 numeric ($array=null)
 pushDiff ($array=null, $array2=null)
 remove ($list, $path=null)
 reverse ($object)

Public Attributes

 $value = array()

Detailed Description

Definition at line 35 of file set.php.


Member Function Documentation

Set::check ( data,
path = null 
)

Checks if a particular path is set in an array

Parameters:
mixed $data Data to check on
mixed $path A dot-separated string.
Returns:
boolean true if path is found, false otherwise public

Definition at line 497 of file set.php.

References $data.

Set::combine ( data,
path1 = null,
path2 = null,
groupPath = null 
)

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.

Parameters:
array $data Array from where to extract keys and values
mixed $path1 As an array, or as a dot-separated string.
mixed $path2 As an array, or as a dot-separated string.
string $groupPath As an array, or as a dot-separated string.
Returns:
array Combined array public

Definition at line 699 of file set.php.

References $data, extract(), and format().

Set::contains ( val1,
val2 = null 
)

Determines if one Set or array contains the exact keys and values of another.

Parameters:
array $val1 First value
array $val2 Second value
Returns:
boolean true if $val1 contains $val2, false otherwise public

Definition at line 586 of file set.php.

Set::countDim ( array = null,
all = false,
count = 0 
)

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.

Parameters:
array $array Array to count dimensions on
boolean $all Set to true to count the dimension considering all elements in array
integer $count Start the dimension count at this number
Returns:
integer The number of dimensions in $array public

Definition at line 617 of file set.php.

Set::diff ( val1,
val2 = null 
)

Computes the difference between a Set and an array, two Sets, or two arrays

Parameters:
mixed $val1 First value
mixed $val2 Second value
Returns:
array Computed difference public

Definition at line 529 of file set.php.

Set::enum ( select,
list = null 
)

Return a value from an array list if the key exists.

If a comma separated $list is passed arrays are numeric with the key of the first being 0 $list = 'no, yes' would translate to $list = array(0 => 'no', 1 => 'yes');

If an array is used, keys can be strings example: array('no' => 0, 'yes' => 1);

$list defaults to 0 = no 1 = yes if param is not passed

Parameters:
mixed $select Key in $list to return
mixed $list can be an array or a comma-separated list.
Returns:
string the value of the array key or null if no match public

Definition at line 286 of file set.php.

References normalize().

Set::extract ( data,
path = null 
)

Gets a value from an array or object that maps a given path. The special {n}, as seen in the Model::generateList method, is taken care of here.

Parameters:
array $data Array from where to extract
mixed $path As an array, or as a dot-separated string.
Returns:
array Extracted data public

Definition at line 366 of file set.php.

References $data.

Referenced by CakeSession::check(), combine(), AclNode::delete(), format(), Model::generateList(), DboMysql::index(), DboSource::name(), CakeSession::read(), and CakeSession::write().

Set::filter ( var,
isArray = false 
)

Filters empty elements out of a route array, excluding '0'.

Parameters:
mixed $var Either an array to filter, or value when in callback
boolean $isArray Force to tell $var is an array when $var is empty
Returns:
mixed Either filtered array, or true/false when in callback public

Definition at line 116 of file set.php.

Set::format ( data,
format,
keys 
)

Returns a series of values extracted from an array, formatted in a format string.

Parameters:
array $data Source array from which to extract the data
string $format Format string into which values will be inserted, see sprintf()
array $keys An array containing one or more Set::extract()-style key paths
Returns:
array An array of strings extracted from $keys and formatted with $format public

Definition at line 310 of file set.php.

References $args, $data, and extract().

Referenced by combine().

& Set::get (  ) 

Returns the contents of the Set object

Returns:
array public

Definition at line 61 of file set.php.

Set::insert ( list,
path,
data = null 
)

Inserts $data into an array as defined by $path.

Parameters:
mixed $list Where to insert into
mixed $path A dot-separated string.
array $data Data to insert
Returns:
array public

Definition at line 424 of file set.php.

References $data.

Referenced by CakeSession::write().

Set::isEqual ( val1,
val2 = null 
)

Determines if two Sets or arrays are equal

Parameters:
array $val1 First value
array $val2 Second value
Returns:
boolean true if they are equal, false otherwise public

Definition at line 570 of file set.php.

Set::map ( class = 'stdClass',
tmp = 'stdClass' 
)

Maps the contents of the Set object to an object hierarchy. Maintains numeric keys as arrays of objects

Parameters:
string $class A class name of the type of object to map to
string $tmp A temporary class name used as $class if $class is an array
Returns:
object Hierarchical object public

Definition at line 164 of file set.php.

Set::merge ( arr1,
arr2 = null 
)

This function 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). See the unit test for more information.

Note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.

Parameters:
array $arr1 Array to be merged
array $arr2 Array to merge with
Returns:
array Merged array public

Definition at line 76 of file set.php.

References $args.

Set::normalize ( list,
assoc = true,
sep = ',',
trim = true 
)

Normalizes a string or array list.

Parameters:
mixed $list List to normalize
boolean $assoc If true, $list will be converted to an associative array
string $sep If $list is a string, it will be split into an array with $sep
boolean $trim If true, separated strings will be trimmed
Returns:
array public

Definition at line 650 of file set.php.

Referenced by enum().

Set::numeric ( array = null  ) 

Checks to see if all the values in the array are numeric

Parameters:
array $array The array to check. If null, the value of the current Set object
Returns:
boolean true if values are numeric, false otherwise public

Definition at line 255 of file set.php.

Referenced by DboSource::fields().

Set::pushDiff ( array = null,
array2 = null 
)

Pushes the differences in $array2 onto the end of $array

Parameters:
mixed $array Original array
mixed $array2 Differences to push
Returns:
array Combined array public

Definition at line 135 of file set.php.

References $value.

Set::remove ( list,
path = null 
)

Removes an element from a Set or array as defined by $path.

Parameters:
mixed $list From where to remove
mixed $path A dot-separated string.
Returns:
array Array with $path removed from its value public

Definition at line 458 of file set.php.

Referenced by CakeSession::del().

Set::reverse ( object  ) 

Converts an object into an array

Parameters:
object $object
Returns:
array

Definition at line 762 of file set.php.

References Inflector::underscore().


Member Data Documentation

Set::$value = array()

Definition at line 42 of file set.php.

Referenced by pushDiff().


The documentation for this class was generated from the following file: