public function match($expression)
{
if (is_callable($expression)) {
$expressionConfigurator = $expression;
$expression = new Expression();
call_user_func($expressionConfigurator, $expression);
}
if ($expression instanceof Expression) {
$expression = $expression->toArray();
} elseif (!is_array($expression)) {
throw new Exception('Must be array, callable or instance of \\Sokil\\Mongo\\Expression');
}
$this->addStage('$match', $expression);
return $this;
}
public function testPipeline_MatchArray() { $pipeline = new Pipeline($this->collection); $pipeline->match(array('a' => 1, 'b' => array('$lt' => 12))); $this->assertEquals('[{"$match":{"a":1,"b":{"$lt":12}}}]', (string) $pipeline); }