From 00a2c8e09c2f0a755beb352166aad847463a7637 Mon Sep 17 00:00:00 2001 From: flip111 Date: Wed, 23 Apr 2014 16:50:15 +0200 Subject: [PATCH] improved error handling for invalid association values Possibly to do: 1. Make custom Exception for line 713 2. Make custom Exception for line 817 3. Does the object check on line 816 slow down the code too much? Alternatively a try-catch could be put around line 1415 or higher up. --- lib/Doctrine/ORM/UnitOfWork.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 5c2eb7bc0..0fb3cca05 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -728,7 +728,11 @@ class UnitOfWork implements PropertyChangedListener continue; } - $this->computeAssociationChanges($assoc, $val); + try { + $this->computeAssociationChanges($assoc, $val); + } catch (\Exception $ex) { + throw new Exception('Expected an Object for relation '.get_class($entity).'::'.$assoc['fieldName'].' got '.gettype($ex->value).' '.var_export($ex->value, true).' instead.'); + } if ( ! isset($this->entityChangeSets[$oid]) && $assoc['isOwningSide'] && @@ -830,6 +834,12 @@ class UnitOfWork implements PropertyChangedListener $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($unwrappedValue as $key => $entry) { + if (! is_object($entry)) { + $ex = new \Exception(gettype($entry) . ' ' . var_export($entry, true).' is not an Object.'); + $ex->value = $entry; + throw $ex; + } + $state = $this->getEntityState($entry, self::STATE_NEW); if ( ! ($entry instanceof $assoc['targetEntity'])) {