Refactored the SqlValueVisitor to move all type processing to the entity persister.
This commit is contained in:
parent
e0d16331a4
commit
959c4f026f
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user