1
0
mirror of synced 2025-01-30 12:01:44 +03:00

Optimized and refactored code for getParameterValue in Doctrine\ORM\Query.

This commit is contained in:
Guilherme Blanco 2011-09-02 13:53:53 -03:00
parent 3b3186ee98
commit f29c907f41

View File

@ -293,28 +293,29 @@ final class Query extends AbstractQuery
*/ */
private function processParameterValue($value) private function processParameterValue($value)
{ {
if (is_array($value)) { switch (true) {
for ($i = 0, $l = count($value); $i < $l; $i++) { case is_array($value):
$paramValue = $this->processParameterValue($value[$i]); for ($i = 0, $l = count($value); $i < $l; $i++) {
$paramValue = $this->processParameterValue($value[$i]);
// TODO: What about Entities that have composite primary key?
$value[$i] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue;
}
return array($value);
// TODO: What about Entities that have composite primary key? case is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value)):
$value[$i] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue; if ($this->_em->getUnitOfWork()->getEntityState($value) === UnitOfWork::STATE_MANAGED) {
} return array_values($this->_em->getUnitOfWork()->getEntityIdentifier($value));
}
return array($value);
$class = $this->_em->getClassMetadata(get_class($value));
return array_values($class->getIdentifierValues($value));
default:
return array($value);
} }
if ( ! (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value)))) {
return array($value);
}
if ($this->_em->getUnitOfWork()->getEntityState($value) === UnitOfWork::STATE_MANAGED) {
return array_values($this->_em->getUnitOfWork()->getEntityIdentifier($value));
}
$class = $this->_em->getClassMetadata(get_class($value));
return array_values($class->getIdentifierValues($value));
} }
/** /**