Set Class Reference

Inheritance diagram for Set:

Object List of all members.

Public Member Functions

 __array ($array)
 __flatten ($results, $key=null)
get ()

Static Public Member Functions

 __map (&$array, $class, $primary=false)
 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)
 flatten ($data, $separator= '.')
 format ($data, $format, $keys)
 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, $array2)
 remove ($list, $path=null)
 reverse ($object)
 sort ($data, $path, $dir)

Public Attributes

 $value = array()

Detailed Description

Definition at line 33 of file set.php.


Member Function Documentation

Set::__array ( array  ) 

Get the array value of $array. If $array is null, it will return the current array Set holds. If it is an object of type Set, it will return its value. If it is another object, its object variables. If it is anything else but an array, it will return an array whose first element is $array.

Parameters:
mixed $array Data from where to get the array.
Returns:
array Array from $array. private

Definition at line 147 of file set.php.

Set::__flatten ( results,
key = null 
)

Flattens an array for sorting

Parameters:
array $results
string $key
Returns:
array private

Definition at line 1066 of file set.php.

References $id.

Referenced by sort().

Set::__map ( &$  array,
class,
primary = false 
) [static]

Maps the given value as an object. If $value is an object, it returns $value. Otherwise it maps $value as an object of type $class, and if primary assign _name_ $key on first array. If $value is not empty, it will be used to set properties of returned object (recursively). If $key is numeric will maintain array structure

Parameters:
mixed $value Value to map
string $class Class name
boolean $primary whether to assign first array key as the _name_
Returns:
mixed Mapped object private

Definition at line 173 of file set.php.

References $out, $value, and countDim().

Referenced by map().

Set::check ( data,
path = null 
) [static]

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

References $path.

Set::classicExtract ( data,
path = null 
) [static]

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

References $path, App::import(), and String::tokenize().

Referenced by extract().

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

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:
mixed $data Array or object 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 929 of file set.php.

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

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

Set::contains ( val1,
val2 = null 
) [static]

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

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

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

Referenced by __map(), and FormHelper::create().

Set::diff ( val1,
val2 = null 
) [static]

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

References $out.

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

Set::enum ( select,
list = null 
) [static]

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

References normalize().

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

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:

Other limitations:

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

References $path, a(), classicExtract(), and matches().

Referenced by Model::__saveMulti(), Model::_findNeighbors(), Model::_findThreaded(), DboSource::_matchRecords(), AclBehavior::afterDelete(), ModelTask::bakeTest(), check(), DbAcl::check(), combine(), AclShell::create(), Model::deleteAll(), format(), DbAcl::getAclLink(), DboMysqlBase::index(), ConsoleShell::main(), matches(), DboSource::name(), read(), sort(), and write().

Set::filter ( var,
isArray = false 
) [static]

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

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

Set::flatten ( data,
separator = '.' 
) [static]

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').

Parameters:
array $data Array to flatten
string $separator String used to separate array key elements in a path, defaults to '.'
Returns:
array public

Definition at line 1034 of file set.php.

References $path.

Set::format ( data,
format,
keys 
) [static]

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

References $out, and extract().

Referenced by combine().

& Set::get (  ) 

Deprecated, Set class should be called statically

Definition at line 1114 of file set.php.

Set::insert ( list,
path,
data = null 
) [static]

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

References $path.

Referenced by write().

Set::isEqual ( val1,
val2 = null 
) [static]

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

Set::map ( class = 'stdClass',
tmp = 'stdClass' 
) [static]

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

References __map().

Referenced by XmlNode::append().

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

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

References extract().

Referenced by extract().

Set::merge ( arr1,
arr2 = null 
) [static]

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

Referenced by HttpSocket::__construct(), Model::__construct(), Controller::__mergeVars(), Component::_loadComponents(), 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 
) [static]

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 Controller::__mergeVars(), Component::_loadComponents(), enum(), and BehaviorCollection::init().

Set::numeric ( array = null  )  [static]

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

Referenced by DboSource::fields(), and Model::saveAll().

Set::pushDiff ( array,
array2 
) [static]

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

References $value.

Referenced by I18n::__bindTextDomain(), __initPluralRules(), __initSingularRules(), and DboSource::__mergeHasMany().

Set::remove ( list,
path = null 
) [static]

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

References $path.

Referenced by del().

Set::reverse ( object  )  [static]

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

References $out.

Referenced by Model::set().

Set::sort ( data,
path,
dir 
) [static]

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

References $path, __flatten(), and extract().


Member Data Documentation

Set::$value = array()

Deprecated

Definition at line 38 of file set.php.

Referenced by __map(), and pushDiff().


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7