mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Move Set::check across.
This commit is contained in:
parent
771efd950e
commit
aa4dca6c0c
2 changed files with 45 additions and 1 deletions
|
@ -1046,4 +1046,32 @@ class Set2Test extends CakeTestCase {
|
|||
$this->assertFalse(isset($result[0]['Article']['body']));
|
||||
}
|
||||
|
||||
/**
|
||||
* testCheck method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheck() {
|
||||
$set = array(
|
||||
'My Index 1' => array('First' => 'The first item')
|
||||
);
|
||||
$this->assertTrue(Set2::check($set, 'My Index 1.First'));
|
||||
$this->assertTrue(Set2::check($set, 'My Index 1'));
|
||||
|
||||
$set = array(
|
||||
'My Index 1' => array(
|
||||
'First' => array(
|
||||
'Second' => array(
|
||||
'Third' => array(
|
||||
'Fourth' => 'Heavy. Nesting.'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertTrue(Set2::check($set, 'My Index 1.First.Second'));
|
||||
$this->assertTrue(Set2::check($set, 'My Index 1.First.Second.Third'));
|
||||
$this->assertTrue(Set2::check($set, 'My Index 1.First.Second.Third.Fourth'));
|
||||
$this->assertFalse(Set2::check($set, 'My Index 1.First.Seconds.Third.Fourth'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,8 +350,24 @@ class Set2 {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether or not a given path exists in $data.
|
||||
* This method uses the same path syntax as Set2::extract()
|
||||
*
|
||||
* Checking for paths that could target more than one element will
|
||||
* make sure that at least one matching element exists.
|
||||
*
|
||||
* @param array $data The data to check.
|
||||
* @param string $path The path to check for.
|
||||
* @return boolean Existence of path.
|
||||
* @see Set2::extract()
|
||||
*/
|
||||
public static function check(array $data, $path) {
|
||||
|
||||
$results = self::extract($data, $path);
|
||||
if (!is_array($results)) {
|
||||
return false;
|
||||
}
|
||||
return count($results) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue