1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Refactored the SqlValueVisitor to move all type processing to the entity persister.

This commit is contained in:
Josiah Truasheim 2012-08-31 20:58:16 +07:00
parent e0d16331a4
commit 959c4f026f
2 changed files with 17 additions and 46 deletions

View File

@ -809,17 +809,23 @@ class BasicEntityPersister
}
$persister = $this;
$valueVisitor = new SqlValueVisitor(
function ($field, $value) use($persister) {
return $persister->getType($field, $value);
},
function ($value) use($persister) {
return $persister->getValue($value);
}
);
$valueVisitor = new SqlValueVisitor();
$valueVisitor->dispatch($expression);
return $valueVisitor->getParamsAndTypes();
list($values, $types) = $valueVisitor->getParamsAndTypes();
$sqlValues = array();
foreach ($values as $value) {
$sqlValues[] = $this->getValue($value);
}
$sqlTypes = array();
foreach ($types as $type) {
list($field, $value) = $type;
$sqlTypes[] = $this->getType($field, $value);
}
return array($sqlValues, $sqlTypes);
}
/**

View File

@ -46,38 +46,6 @@ class SqlValueVisitor extends ExpressionVisitor
*/
private $types = array();
/**
* Type Callback
*
* Called by this visitor to determine the type of a value
*
* @var callable
*/
private $typeCallback;
/**
* Value Callback
*
* Called by this visitor to generate a sql value from the given value
*
* Callback is passed two parameters:
* - `Field` name of the field in a comparison
* - `Value` value in a comparison
*
* @var callable
*/
private $valueCallback;
/**
* @param callable $typeCallback Type Resolution Callback
* @param callable $valueCallback Value Resolution Callback
*/
public function __construct($typeCallback, $valueCallback)
{
$this->typeCallback = $typeCallback;
$this->valueCallback = $valueCallback;
}
/**
* Convert a comparison expression into the target query language output
*
@ -87,14 +55,11 @@ class SqlValueVisitor extends ExpressionVisitor
*/
public function walkComparison(Comparison $comparison)
{
$typeCallback = $this->typeCallback;
$valueCallback = $this->valueCallback;
$value = $comparison->getValue()->getValue();
$field = $comparison->getField();
$this->values[] = $valueCallback($value);
$this->types[] = $typeCallback($field, $value);
$this->values[] = $value;
$this->types[] = array($field, $value);
}
/**