Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rename set::getValue to set::get - and make it public
  • Loading branch information
AD7six committed Jan 12, 2012
1 parent 941d503 commit 7414d0f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/Cake/Utility/Set.php
Expand Up @@ -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]);
Expand All @@ -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]);
}
Expand All @@ -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) {
Expand Down

0 comments on commit 7414d0f

Please sign in to comment.