Modified Set::extract to be available from combine and other functions as well

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6659 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-04-13 18:46:27 +00:00
parent de4807e726
commit 9f040bd395
2 changed files with 15 additions and 0 deletions

View file

@ -383,9 +383,17 @@ class Set extends Object {
* @access public
*/
function extract($path, $data = null, $options = array()) {
if (is_string($data) && $data{0} == '/') {
$tmp = $path;
$path = $data;
$data = $tmp;
}
if (is_array($path) || empty($data) || is_object($path) || empty($path)) {
return Set::classicExtract($path, $data);
}
if ($path == '/') {
return $data;
}
$contexts = $data;
$options = am(array('flatten' => true), $options);
if (!isset($contexts[0])) {

View file

@ -487,6 +487,13 @@ class SetTest extends UnitTestCase {
$expected = array(1, 2, 4, 5);
$r = Set::extract('/Comment[id!=3]/id', $common);
$this->assertEqual($r, $expected);
$r = Set::extract('/', $common);
$this->assertEqual($r, $common);
$expected = array(1, 2, 4, 5);
$r = Set::extract($common, '/Comment[id!=3]/id');
$this->assertEqual($r, $expected);
}
/**
* undocumented function