@@ -36,7 +36,8 @@ class Set2 {
36
36
* but is faster for simple operations.
37
37
*
38
38
* @param array $data Array of data to operate on.
39
- * @param string $path The path being searched for.
39
+ * @param mixed $path The path being searched for. Either a dot
40
+ * separated string, or an array of path segments.
40
41
* @return mixed The value fetched from the array, or null.
41
42
*/
42
43
public static function get (array $ data , $ path ) {
@@ -484,19 +485,21 @@ public static function check(array $data, $path) {
484
485
}
485
486
486
487
/**
487
- * Recursively filters empty elements out of a route array, excluding '0' .
488
+ * Recursively filters a data set .
488
489
*
489
490
* @param array $data Either an array to filter, or value when in callback
491
+ * @param callable $callback A function to filter the data with. Defaults to
492
+ * `self::_filter()` Which strips out all non-zero empty values.
490
493
* @return array Filtered array
491
494
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::filter
492
495
*/
493
- public static function filter (array $ data ) {
496
+ public static function filter (array $ data, $ callback = array ( ' self ' , ' _filter ' ) ) {
494
497
foreach ($ data as $ k => $ v ) {
495
498
if (is_array ($ v )) {
496
- $ data [$ k ] = self ::filter ($ v );
499
+ $ data [$ k ] = self ::filter ($ v, $ callback );
497
500
}
498
501
}
499
- return array_filter ($ data , array ( ' self ' , ' _filter ' ) );
502
+ return array_filter ($ data , $ callback );
500
503
}
501
504
502
505
/**
@@ -817,16 +820,21 @@ public static function normalize(array $data, $assoc = true) {
817
820
/**
818
821
* Takes in a flat array and returns a nested array
819
822
*
820
- * @param mixed $data
823
+ * ### Options:
824
+ *
825
+ * - `children` The key name to use in the resultset for children.
826
+ * - `idPath` The path to a key that identifies each entry. Should be
827
+ * compatible with Set2::extract(). Defaults to `{n}.$alias.id`
828
+ * - `parentPath` The path to a key that identifies the parent of each entry.
829
+ * Should be compatible with Set2::extract(). Defaults to `{n}.$alias.parent_id`
830
+ * - `root` The id of the desired top-most result.
831
+ *
832
+ * @param mixed $data The data to nest.
821
833
* @param array $options Options are:
822
- * children - the key name to use in the resultset for children
823
- * idPath - the path to a key that identifies each entry
824
- * parentPath - the path to a key that identifies the parent of each entry
825
- * root - the id of the desired top-most result
826
834
* @return array of results, nested
827
- * @link
835
+ * @see Set::extract()
828
836
*/
829
- public static function nest ($ data , $ options = array ()) {
837
+ public static function nest (array $ data , $ options = array ()) {
830
838
if (!$ data ) {
831
839
return $ data ;
832
840
}
0 commit comments