1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Store QueryExpressionVisitor parameters as array

This commit is contained in:
Kirill chEbba Chebunin 2012-08-20 19:54:11 +04:00
parent 433d208572
commit 1c2f2b5c13
2 changed files with 16 additions and 8 deletions

View file

@ -45,7 +45,7 @@ class QueryExpressionVisitor extends ExpressionVisitor
); );
private $expr; private $expr;
private $parameters; private $parameters = array();
/** /**
* Constructor with internal initialization * Constructor with internal initialization
@ -53,7 +53,6 @@ class QueryExpressionVisitor extends ExpressionVisitor
public function __construct() public function __construct()
{ {
$this->expr = new Expr(); $this->expr = new Expr();
$this->parameters = new ArrayCollection();
} }
/** /**
@ -64,7 +63,7 @@ class QueryExpressionVisitor extends ExpressionVisitor
*/ */
public function getParameters() public function getParameters()
{ {
return $this->parameters; return new ArrayCollection($this->parameters);
} }
/** /**
@ -121,11 +120,11 @@ class QueryExpressionVisitor extends ExpressionVisitor
switch ($comparison->getOperator()) { switch ($comparison->getOperator()) {
case Comparison::IN: case Comparison::IN:
$this->parameters->add($parameter); $this->parameters[] = $parameter;
return $this->expr->in($comparison->getField(), $placeholder); return $this->expr->in($comparison->getField(), $placeholder);
case Comparison::NIN: case Comparison::NIN:
$this->parameters->add($parameter); $this->parameters[] = $parameter;
return $this->expr->notIn($comparison->getField(), $placeholder); return $this->expr->notIn($comparison->getField(), $placeholder);
case Comparison::EQ: case Comparison::EQ:
@ -133,20 +132,20 @@ class QueryExpressionVisitor extends ExpressionVisitor
if ($this->walkValue($comparison->getValue()) === null) { if ($this->walkValue($comparison->getValue()) === null) {
return $this->expr->isNull($comparison->getField()); return $this->expr->isNull($comparison->getField());
} }
$this->parameters->add($parameter); $this->parameters[] = $parameter;
return $this->expr->eq($comparison->getField(), $placeholder); return $this->expr->eq($comparison->getField(), $placeholder);
case Comparison::NEQ: case Comparison::NEQ:
if ($this->walkValue($comparison->getValue()) === null) { if ($this->walkValue($comparison->getValue()) === null) {
return $this->expr->isNotNull($comparison->getField()); return $this->expr->isNotNull($comparison->getField());
} }
$this->parameters->add($parameter); $this->parameters[] = $parameter;
return $this->expr->neq($comparison->getField(), $placeholder); return $this->expr->neq($comparison->getField(), $placeholder);
default: default:
$operator = self::convertComparisonOperator($comparison->getOperator()); $operator = self::convertComparisonOperator($comparison->getOperator());
if ($operator) { if ($operator) {
$this->parameters->add($parameter); $this->parameters[] = $parameter;
return new Expr\Comparison( return new Expr\Comparison(
$comparison->getField(), $comparison->getField(),
$operator, $operator,

View file

@ -134,4 +134,13 @@ class QueryExpressionVisitorTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals('value', $this->visitor->walkValue(new Value('value'))); $this->assertEquals('value', $this->visitor->walkValue(new Value('value')));
} }
public function testClearParameters()
{
$this->visitor->getParameters()->add(new Parameter('field', 'value'));
$this->visitor->clearParameters();
$this->assertCount(0, $this->visitor->getParameters());
}
} }