From 88e071d22d8ce1b88fd5f7d67fd6a72980422430 Mon Sep 17 00:00:00 2001 From: flip111 Date: Tue, 13 Jan 2015 10:12:14 +0100 Subject: [PATCH] moved exception constructors out of UoW --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0fb3cca05..3ac943cba 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -731,7 +731,7 @@ class UnitOfWork implements PropertyChangedListener 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.'); + throw ORMInvalidArgumentException::invalidAssociation($entity, $assoc['fieldName'], $ex->value); } if ( ! isset($this->entityChangeSets[$oid]) && @@ -834,10 +834,8 @@ 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; + if (! ($entry instanceof $assoc['targetEntity']))) { + throw ORMInvalidArgumentException::invalidAssociation($entry); } $state = $this->getEntityState($entry, self::STATE_NEW);