mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
cleaning up some Set::extract, adding tests for empty data and results. Removing some checks from Cache engine.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8097 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b184d0705d
commit
198548092b
3 changed files with 35 additions and 20 deletions
|
@ -142,10 +142,6 @@ class Cache extends Object {
|
|||
* @static
|
||||
*/
|
||||
function engine($name = 'File', $settings = array()) {
|
||||
if (!$name || Configure::read('Cache.disable')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cacheClass = $name . 'Engine';
|
||||
$_this =& Cache::getInstance();
|
||||
if (!isset($_this->_Engine[$name])) {
|
||||
|
|
|
@ -369,16 +369,16 @@ class Set extends Object {
|
|||
* @static
|
||||
*/
|
||||
function extract($path, $data = null, $options = array()) {
|
||||
if (empty($data) && is_string($path) && $path{0} === '/') {
|
||||
if (is_string($data)) {
|
||||
$tmp = $data;
|
||||
$data = $path;
|
||||
$path = $tmp;
|
||||
}
|
||||
if (empty($data)) {
|
||||
return 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 (strpos($path, '/') === false) {
|
||||
return Set::classicExtract($data, $path);
|
||||
}
|
||||
if ($path === '/') {
|
||||
return $data;
|
||||
|
|
|
@ -1042,6 +1042,25 @@ class SetTest extends CakeTestCase {
|
|||
$this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published'));
|
||||
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* testSetExtractReturnsEmptyArray method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSetExtractReturnsEmptyArray() {
|
||||
|
||||
$this->assertEqual(Set::extract(array(), '/Post/id'), array());
|
||||
|
||||
$this->assertEqual(Set::extract('/Post/id', array()), array());
|
||||
|
||||
$this->assertEqual(Set::extract('/Post/id', array(
|
||||
array('Post' => array('name' => 'bob')),
|
||||
array('Post' => array('name' => 'jim'))
|
||||
)), array());
|
||||
|
||||
}
|
||||
/**
|
||||
* testClassicExtract method
|
||||
|
|
Loading…
Add table
Reference in a new issue