mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Add attribute pattern matching.
This commit is contained in:
parent
cbfa938303
commit
31181f58d6
2 changed files with 22 additions and 7 deletions
|
@ -783,4 +783,17 @@ class Set2Test extends CakeTestCase {
|
|||
$this->assertEquals(4, $expected[0]['user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute pattern matching.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExtractAttributePattern() {
|
||||
$data = self::articleData();
|
||||
|
||||
$result = Set2::extract($data, '{n}.Article[title=/^First/]');
|
||||
$expected = array($data[0]['Article']);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -163,7 +163,6 @@ class Set2 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Filter for attributes.
|
||||
|
@ -211,17 +210,22 @@ class Set2 {
|
|||
|
||||
// Presence test.
|
||||
if (empty($op) && empty($val) && !isset($data[$attr])) {
|
||||
$ok = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Empty attribute = fail.
|
||||
if (!isset($data[$attr])) {
|
||||
$ok = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$prop = isset($data[$attr]) ? $data[$attr] : null;
|
||||
|
||||
if (
|
||||
// Pattern matches and other operators.
|
||||
if ($op === '=' && $val && $val[0] === '/') {
|
||||
if (!preg_match($val, $prop)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (
|
||||
($op === '=' && $prop != $val) ||
|
||||
($op === '!=' && $prop == $val) ||
|
||||
($op === '>' && $prop <= $val) ||
|
||||
|
@ -229,11 +233,9 @@ class Set2 {
|
|||
($op === '>=' && $prop < $val) ||
|
||||
($op === '<=' && $prop > $val)
|
||||
) {
|
||||
$ok = false;
|
||||
}
|
||||
if (!$ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue