Change the array access used in UniqueEntityValidator

convert iterator to array if it isnt already (mongodb)

More specific if

Dont do iterator_to_array if object implements \ArrayAccess

CS fix
This commit is contained in:
Henrik Bjørnskov 2012-02-06 08:57:54 +01:00
parent 1bef14a02a
commit 928e352d09
1 changed files with 7 additions and 1 deletions

View File

@ -94,11 +94,17 @@ class UniqueEntityValidator extends ConstraintValidator
$repository = $em->getRepository($className);
$result = $repository->findBy($criteria);
// MongoDB will return a Cursor so we need to change it to an array
// so it is compatible with the orm returning an array
if ($result instanceof \Iterator && !$result instanceof \ArrayAccess) {
$result = iterator_to_array($result);
}
/* If no entity matched the query criteria or a single entity matched,
* which is the same as the entity being validated, the criteria is
* unique.
*/
if (0 === count($result) || (1 === count($result) && $entity === $result[0])) {
if (0 === count($result) || (1 === count($result) && $entity === reset($result))) {
return true;
}