Permalink
Browse files

Support Comparison::CONTAINS in doctrine/collections 1.1+

  • Loading branch information...
1 parent 4b32476 commit 9d622afc84ea55a01eb4e7f84d9366dc0e3d9636 @jmikola jmikola committed Oct 30, 2013
View
@@ -15,7 +15,7 @@
"php": ">=5.3.2",
"symfony/console": "~2.0",
"doctrine/annotations": "~1.0",
- "doctrine/collections": "~1.0",
+ "doctrine/collections": "~1.1",
"doctrine/common": "2.4.*",
"doctrine/cache": "~1.0",
"doctrine/inflector": "~1.0",
@@ -101,6 +101,13 @@ public function walkComparison(Comparison $comparison)
->field($comparison->getField())
->{$method}($this->walkValue($comparison->getValue()));
+ case Comparison::CONTAINS:
+ $value = $this->walkValue($comparison->getValue());
+
+ return $this->builder->expr()
+ ->field($comparison->getField())
+ ->equals(new \MongoRegex('/' . preg_quote($value, '/') . '/'));
+
default:
throw new \RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
}
@@ -38,6 +38,7 @@ public function provideComparisons()
return array(
array($builder->eq('field', 'value'), array('field' => 'value')),
+ array($builder->contains('field', 'value'), array('field' => new \MongoRegex('/value/'))),
array($builder->gt('field', 'value'), array('field' => array('$gt' => 'value'))),
array($builder->gte('field', 'value'), array('field' => array('$gte' => 'value'))),
array($builder->in('field', array(1, 2)), array('field' => array('$in' => array(1, 2)))),

0 comments on commit 9d622af

Please sign in to comment.