From 9f040bd3955063dce269ef84cb293a9bdd7cbe54 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Sun, 13 Apr 2008 18:46:27 +0000 Subject: [PATCH] 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 --- cake/libs/set.php | 8 ++++++++ cake/tests/cases/libs/set.test.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/cake/libs/set.php b/cake/libs/set.php index e12c877d4..55b8c9f7a 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -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])) { diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index ffc6172c9..202a401d5 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -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