diff --git a/src/Query.php b/src/Query.php index 3600397..bcd54d2 100755 --- a/src/Query.php +++ b/src/Query.php @@ -19,6 +19,9 @@ class Query '<' => 'lessThan', '<=' => 'lessThanOrEqualTo', 'in' => 'containedIn', + '%%' => 'matches', + '%s' => 'startsWith', + 's%' => 'endsWith' ]; /** @@ -170,11 +173,30 @@ public function orQuery() * @return $this */ public function where($key, $operator = null, $value = null) - { + { if (is_array($key)) { $where = $key; - + foreach ($where as $key => $value) { + if (is_array($value)) { + + if (count($value) !== 3) { + continue; + } + + if (!array_key_exists($value[1], self::OPERATORS)) { + throw new Exception("Invalid operator: " . $value[1]); + } + + if (self::OPERATORS[$value[1]] === 'matches') { + call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2], 'i'); + } else { + call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2]); + } + + continue; + } + if ($value instanceof ObjectModel) { $value = $value->getParseObject(); } @@ -493,7 +515,7 @@ public function containedIn($key, $values) if (!is_array($values) && !$values instanceof Traversable) { $values = [ $values ]; } - + foreach ($values as $k => $value) { if ($value instanceof ObjectModel) { $values[$k] = $value->getParseObject();