1
0
mirror of synced 2025-01-30 20:11:49 +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,7 +293,8 @@ final class Query extends AbstractQuery
*/ */
private function processParameterValue($value) private function processParameterValue($value)
{ {
if (is_array($value)) { switch (true) {
case is_array($value):
for ($i = 0, $l = count($value); $i < $l; $i++) { for ($i = 0, $l = count($value); $i < $l; $i++) {
$paramValue = $this->processParameterValue($value[$i]); $paramValue = $this->processParameterValue($value[$i]);
@ -302,12 +303,8 @@ final class Query extends AbstractQuery
} }
return array($value); return array($value);
}
if ( ! (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value)))) {
return array($value);
}
case is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value)):
if ($this->_em->getUnitOfWork()->getEntityState($value) === UnitOfWork::STATE_MANAGED) { if ($this->_em->getUnitOfWork()->getEntityState($value) === UnitOfWork::STATE_MANAGED) {
return array_values($this->_em->getUnitOfWork()->getEntityIdentifier($value)); return array_values($this->_em->getUnitOfWork()->getEntityIdentifier($value));
} }
@ -315,6 +312,10 @@ final class Query extends AbstractQuery
$class = $this->_em->getClassMetadata(get_class($value)); $class = $this->_em->getClassMetadata(get_class($value));
return array_values($class->getIdentifierValues($value)); return array_values($class->getIdentifierValues($value));
default:
return array($value);
}
} }
/** /**