Permalink
Browse files

rename set::getValue to set::get - and make it public

  • Loading branch information...
1 parent 941d503 commit 7414d0f77b57f986db519d35eb485c32cbd51068 @AD7six AD7six committed Jan 12, 2012
Showing with 14 additions and 7 deletions.
  1. +14 −7 lib/Cake/Utility/Set.php
View
21 lib/Cake/Utility/Set.php
@@ -1146,8 +1146,8 @@ public static function nest($data, $options = array()) {
foreach ($data as $result) {
$result[$options['children']] = array();
- $id = Set::getValue($result, $idKeys);
- $parentId = Set::getValue($result, $parentKeys);
+ $id = Set::get($result, $idKeys);
+ $parentId = Set::get($result, $parentKeys);
if (isset($idMap[$id][$options['children']])) {
$idMap[$id] = array_merge($result, (array)$idMap[$id]);
@@ -1161,10 +1161,10 @@ public static function nest($data, $options = array()) {
}
}
- $root = Set::getValue($return[0], $parentKeys);
+ $root = Set::get($return[0], $parentKeys);
foreach ($return as $i => $result) {
- $parentId = Set::getValue($result, $parentKeys);
+ $parentId = Set::get($result, $parentKeys);
if ($parentId != $root) {
unset($return[$i]);
}
@@ -1174,18 +1174,25 @@ public static function nest($data, $options = array()) {
}
/**
- * A slimmed down set extract
+ * Return the value at the specified position
*
* @param mixed $input an array
* @param mixed $path string or array of array keys
* @return the value at the specified position or null if it doesn't exist
*/
- protected static function getValue($input, $path) {
+ public static function get($input, $path = null) {
if (is_string($path)) {
- $keys = explode('/', trim($path, '/'));
+ if (strpos($path, '/') !== false) {
+ $keys = explode('/', trim($path, '/'));
+ } else {
+ $keys = explode('.', trim($path, '.'));
+ }
} else {
$keys = $path;
}
+ if (!$keys) {
+ return $input;
+ }
$return = $input;
foreach($keys as $key) {

0 comments on commit 7414d0f

Please sign in to comment.