Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
}
if (isset($xmlRoot->{'require-indexes'})) {
$class->setRequireIndexes((boolean) $xmlRoot->{'require-indexes'});
$class->setRequireIndexes('true' === (string) $xmlRoot->{'require-indexes'});
}
if (isset($xmlRoot->{'allow-less-efficient-indexes'})) {
$class->setAllowLessEfficientIndexes($xmlRoot->{'allow-less-efficient-indexes'});
$class->setAllowLessEfficientIndexes('true' === (string) $xmlRoot->{'allow-less-efficient-indexes'});
}
if (isset($xmlRoot->{'slave-okay'})) {
$class->setSlaveOkay((boolean) $xmlRoot->{'slave-okay'});
$class->setSlaveOkay('true' === (string) $xmlRoot->{'slave-okay'});
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
Expand Down
34 changes: 7 additions & 27 deletions lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getFieldsWithEqualityCondition()
foreach ($elemMatchFields as $field) {
$fields[] = $k.'.'.$field;
}
} elseif ($this->isOperator($k, array('and', 'or'))) {
} elseif (in_array($k, array('$and', '$or'))) {
foreach ($v as $q) {
$test = new self($q);
$fields = array_merge($fields, $test->getFieldsWithEqualityCondition());
Expand All @@ -83,7 +83,7 @@ public function getFields()
foreach ($elemMatchFields as $field) {
$fields[] = $k.'.'.$field;
}
} elseif ($this->isOperator($k, array('and', 'or'))) {
} elseif (in_array($k, array('$and', '$or'))) {
foreach ($v as $q) {
$test = new self($q);
$fields = array_merge($fields, $test->getFields());
Expand All @@ -105,7 +105,7 @@ public function getOrClauses()
{
$clauses = array();
foreach ($this->query as $k => $v) {
if ($this->isOperator($k, 'or')) {
if ($k === '$or') {
foreach ($v as $q) {
$test = new self($q);
$foundClauses = $test->getOrClauses();
Expand All @@ -115,7 +115,7 @@ public function getOrClauses()
$clauses[] = $q;
}
}
} elseif ($this->isOperator($k, 'and')) {
} elseif ($k === '$and') {
foreach ($v as $q) {
$test = new self($q);
$foundClauses = $test->getOrClauses();
Expand Down Expand Up @@ -179,7 +179,7 @@ public function getQueryWithoutOrClauses($query = null)
unset($query['$or']);
}
foreach ($query as $k => $v) {
if ($this->isOperator($k, 'and')) {
if ($k === '$and') {
foreach ($v as $i => $q) {
$query[$k][$i] = $this->getQueryWithoutOrClauses($q);
if (empty($query[$k][$i])) {
Expand Down Expand Up @@ -213,11 +213,11 @@ private function getFieldsFromElemMatch(array $elemMatch, $onlyEqualityCondition
{
$fields = array();
foreach ($elemMatch as $fieldName => $value) {
if ($this->isOperator($fieldName, 'where')) {
if ($fieldName === '$where') {
continue;
}

if ($this->isOperator($fieldName, array('and', 'or'))) {
if (in_array($fieldName, array('$and', '$or'))) {
foreach ($value as $q) {
$test = new self($q);
if (!$onlyEqualityConditions) {
Expand All @@ -232,24 +232,4 @@ private function getFieldsFromElemMatch(array $elemMatch, $onlyEqualityCondition
}
return $fields;
}

/**
* Checks if given field(s) is one of given operators
*
* @param string $fieldName
* @param string|array $operator
* @return boolean
*/
private function isOperator($fieldName, $operator)
{
if ( ! is_array($operator)) {
$operator = array($operator);
}
foreach ($operator as $op) {
if ($fieldName === '$' . $op) {
return true;
}
}
return false;
}
}