-
-
Notifications
You must be signed in to change notification settings - Fork 194
Support compare in MongoDB #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
74474fc
9a5873c
e7badc7
22ca1e9
144a217
c944e4d
5d4efd4
cb57ec5
7f7689a
e0897da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -844,21 +844,45 @@ public function buildCondition($condition) | |
return []; | ||
} | ||
if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ... | ||
$operator = strtoupper($condition[0]); | ||
if (isset($builders[$operator])) { | ||
$operator = $condition[0]; | ||
if (strncmp($operator, '$', 1) === 0) { | ||
$method = 'buildSimpleCondition'; | ||
} elseif (isset($builders[strtoupper($operator)])) { | ||
$operator = strtoupper($operator); | ||
$method = $builders[$operator]; | ||
array_shift($condition); | ||
|
||
return $this->$method($operator, $condition); | ||
} else { | ||
throw new InvalidParamException('Found unknown operator in query: ' . $operator); | ||
} | ||
array_shift($condition); | ||
return $this->$method($operator, $condition); | ||
} else { | ||
// hash format: 'column1' => 'value1', 'column2' => 'value2', ... | ||
return $this->buildHashCondition($condition); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Creates a condition on a column-value pair using an abritrary operator | ||
* | ||
* @param string $operator The Mongo operator. Note that Mongo query operators must start with an $ (e.g. `$gt`, `$lt`, etc.) | ||
* @param array $operands The column-value pair | ||
* @return array The generated Mongo condition | ||
* @throws InvalidParamException if $operator does not start with $ or when wrong number of operands have been given. | ||
*/ | ||
public function buildSimpleCondition($operator, $operands) | ||
|
||
{ | ||
if (strncmp($operator, '$', 1) !== 0) { | ||
throw new InvalidParamException('Invalid operator in query: ' . $operator); | ||
} | ||
if (!isset($operands[0], $operands[1])) { | ||
throw new InvalidParamException("Operator '$operator' requires two operands."); | ||
} | ||
|
||
list($name, $value) = $operands; | ||
|
||
return [$name => [$operator => $value]]; | ||
} | ||
|
||
/** | ||
* Creates a condition based on column-value pairs. | ||
* @param array $condition the condition specification. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change for?