Permalink
Browse files

Added some more operators.

Attribute + {n} is still not working.
  • Loading branch information...
markstory committed Jan 23, 2012
1 parent 6c87be9 commit 9269a6dcde813c85eab66b5e90a57a988b4f76e8
Showing with 21 additions and 0 deletions.
  1. +12 −0 lib/Cake/Test/Case/Utility/Set2Test.php
  2. +9 −0 lib/Cake/Utility/Set2.php
@@ -737,4 +737,16 @@ public function testExtractAttributeEquality() {
$this->assertEquals(5, $result[3]['id']);
}
+/**
+ * Test comparison operators.
+ *
+ * @return void
+ */
+ public function testExtractAttributeComparison() {
+ $data = self::articleData();
+
+ $result = Set2::extract($data, '{n}.Comment.{n}.[user_id > 2]');
+ $this->assertEquals($data[0]['Comment'][1], $result);
+ }
+
}
@@ -158,6 +158,7 @@ protected static function _traverse(array &$data, $path, $callback) {
} else {
// attributes
foreach ($item as $k => $v) {
+ debug(array($k => $v));
if (self::_matches(array($k => $v), $token)) {
$next[] = $v;
}
@@ -211,6 +212,14 @@ protected static function _matches(array $data, $selector) {
return $prop == $val;
} elseif ($op === '!=') {
return $prop != $val;
+ } elseif ($op === '>') {
+ return $prop > $val;
+ } elseif ($op === '<') {
+ return $prop < $val;
+ } elseif ($op === '>=') {
+ return $prop >= $val;
+ } elseif ($op === '<=') {
+ return $prop <= $val;
}
}
return false;

0 comments on commit 9269a6d

Please sign in to comment.