Fixed DDC-2003 using closures to reference the functionality of the calling entity persister from the SQL value visitor.
This commit is contained in:
parent
783c53d57c
commit
c7f5d9d77d
@ -808,7 +808,15 @@ class BasicEntityPersister
|
||||
return array(array(), array());
|
||||
}
|
||||
|
||||
$valueVisitor = new SqlValueVisitor($this->_class);
|
||||
$persister = $this;
|
||||
$valueVisitor = new SqlValueVisitor(
|
||||
function ($field, $value) use($persister) {
|
||||
return $persister->getType($field, $value);
|
||||
},
|
||||
function ($value) use($persister) {
|
||||
return $persister->getValue($value);
|
||||
}
|
||||
);
|
||||
$valueVisitor->dispatch($expression);
|
||||
|
||||
return $valueVisitor->getParamsAndTypes();
|
||||
|
@ -47,16 +47,35 @@ class SqlValueVisitor extends ExpressionVisitor
|
||||
private $types = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\ORM\Mapping\ClassMetadata
|
||||
* Type Callback
|
||||
*
|
||||
* Called by this visitor to determine the type of a value
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
private $class;
|
||||
private $typeCallback;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\Mapping\ClassMetadata
|
||||
* 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
|
||||
*/
|
||||
public function __construct(ClassMetadata $class)
|
||||
private $valueCallback;
|
||||
|
||||
/**
|
||||
* @param callable $typeCallback Type Resolution Callback
|
||||
* @param callable $valueCallback Value Resolution Callback
|
||||
*/
|
||||
public function __construct(callable $typeCallback, callable $valueCallback)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->typeCallback = $typeCallback;
|
||||
$this->valueCallback = $valueCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,11 +87,14 @@ class SqlValueVisitor extends ExpressionVisitor
|
||||
*/
|
||||
public function walkComparison(Comparison $comparison)
|
||||
{
|
||||
$typeCallback = $this->typeCallback;
|
||||
$valueCallback = $this->valueCallback;
|
||||
|
||||
$value = $comparison->getValue()->getValue();
|
||||
$field = $comparison->getField();
|
||||
|
||||
$this->values[] = $value;
|
||||
$this->types[] = $this->getType($field, $value);
|
||||
|
||||
$this->values[] = $valueCallback($value);
|
||||
$this->types[] = $typeCallback($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,17 +132,4 @@ class SqlValueVisitor extends ExpressionVisitor
|
||||
{
|
||||
return array($this->values, $this->types);
|
||||
}
|
||||
|
||||
private function getType($field, $value)
|
||||
{
|
||||
$type = isset($this->class->fieldMappings[$field])
|
||||
? Type::getType($this->class->fieldMappings[$field]['type'])->getBindingType()
|
||||
: \PDO::PARAM_STR;
|
||||
|
||||
if (is_array($value)) {
|
||||
$type += Connection::ARRAY_PARAM_OFFSET;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user