1
0
mirror of synced 2025-01-19 06:51:40 +03:00

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.
This commit is contained in:
flip111 2014-04-23 16:50:15 +02:00 committed by Marco Pivetta
parent 84562bca82
commit 00a2c8e09c

View File

@ -728,7 +728,11 @@ class UnitOfWork implements PropertyChangedListener
continue; 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]) && if ( ! isset($this->entityChangeSets[$oid]) &&
$assoc['isOwningSide'] && $assoc['isOwningSide'] &&
@ -830,6 +834,12 @@ class UnitOfWork implements PropertyChangedListener
$targetClass = $this->em->getClassMetadata($assoc['targetEntity']); $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
foreach ($unwrappedValue as $key => $entry) { 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); $state = $this->getEntityState($entry, self::STATE_NEW);
if ( ! ($entry instanceof $assoc['targetEntity'])) { if ( ! ($entry instanceof $assoc['targetEntity'])) {