Skip to content

Commit

Permalink
add more operators
Browse files Browse the repository at this point in the history
  • Loading branch information
nafplann authored Apr 19, 2018
1 parent 5dcee41 commit c8ee2ce
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Query
'<' => 'lessThan',
'<=' => 'lessThanOrEqualTo',
'in' => 'containedIn',
'%%' => 'matches',
'%s' => 'startsWith',
's%' => 'endsWith'
];

/**
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c8ee2ce

Please sign in to comment.