Set Class Reference

Inheritance diagram for Set:

Object

List of all members.


Public Member Functions

 check ($data, $path=null)
 classicExtract ($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 ($path, $data=null, $options=array())
 filter ($var, $isArray=false)
 format ($data, $format, $keys)
get ()
 insert ($list, $path, $data=null)
 isEqual ($val1, $val2=null)
 map ($class= 'stdClass', $tmp= 'stdClass')
 matches ($conditions, $data=array(), $i=null, $length=null)
 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)
 sort ($data, $path, $dir)

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 722 of file set.php.

Set::classicExtract ( data,
path = null 
)

Gets a value from an array or object that is contained in a given path using an array path syntax, i.e.: "{n}.Person.{[a-z]+}" - Where "{n}" represents a numeric key, "Person" represents a string literal, and "{[a-z]+}" (i.e. any string literal enclosed in brackets besides {n} and {s}) is interpreted as a regular expression.

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 564 of file set.php.

References String::tokenize().

Referenced by extract().

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 926 of file set.php.

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

Referenced by Model::_findList(), and TreeBehavior::generatetreelist().

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 813 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 844 of file set.php.

Referenced by FormHelper::create().

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 754 of file set.php.

References $out.

Referenced by DboOracle::queryAssociation(), and PaginatorHelper::url().

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 291 of file set.php.

References normalize().

Set::extract ( path,
data = null,
options = array() 
)

Implements partial support for XPath 2.0. If $path is an array or $data is empty it the call is delegated to Set::classicExtract.

Currently 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[title] (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=/cakephp/i] (Selects the all comments that have a text matching the regex /cakephp/i)
  • /Comment/@* (Selects the all key names of all comments)

Other limitations:

  • Only absolute paths starting with a single '/' are supported right now

Warning: Even so it has plenty of unit tests the XPath support has not gone through a lot of real-world testing. Please report Bugs as you find them. Suggestions for additional features to imlement are also very welcome!

Parameters:
string $path An absolute XPath 2.0 path
string $data An array of data to extract from
string $options Currently only supports 'flatten' which can be disabled for higher XPath-ness
Returns:
array An array of matched items public

Definition at line 390 of file set.php.

References a(), am(), classicExtract(), and matches().

Referenced by Model::_findNeighbors(), DboSource::_matchRecords(), AclBehavior::afterDelete(), ModelTask::bakeTest(), CakeSession::check(), DbAcl::check(), combine(), AclShell::create(), Model::deleteAll(), format(), DbAcl::getAclLink(), DboMysql::index(), matches(), DboSource::name(), CakeSession::read(), sort(), 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.

Referenced by Model::create(), View::entity(), PaginatorHelper::link(), and Helper::setEntity().

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 315 of file set.php.

References $out, 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 649 of file set.php.

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 797 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.

Referenced by XmlNode::append().

Set::matches ( conditions,
data = array(),
i = null,
length = null 
)

This function can be used to see if a single item or a given xpath match certain conditions.

Parameters:
mixed $conditions An array of condition strings or an XPath expression
array $data An array of data to execute the match on
integer $i Optional: The 'nth'-number of the item being matched.
Returns:
boolean public

Definition at line 499 of file set.php.

References extract().

Referenced by extract().

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.

Referenced by HttpSocket::configUri(), ContainableBehavior::containments(), HttpSocket::delete(), HttpSocket::get(), HttpSocket::post(), HttpSocket::put(), HttpSocket::request(), and Model::save().

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 877 of file set.php.

Referenced by Component::_loadComponents(), enum(), and BehaviorCollection::init().

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(), and Model::saveAll().

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 683 of file set.php.

Referenced by CakeSession::del().

Set::reverse ( object  ) 

Converts an object into an array. If $object is no object, reverse will return the same value.

Parameters:
object $object Object to reverse
Returns:
array

Definition at line 993 of file set.php.

References $out, and Inflector::camelize().

Referenced by Model::set().

Set::sort ( data,
path,
dir 
)

Sorts an array by any value, determined by a Set-compatible path

Parameters:
array $data
string $path A Set-compatible path to the array value
string $dir asc/desc
Returns:
array

Definition at line 1097 of file set.php.

References extract().


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: