Commit 69a0b597 authored by romanb's avatar romanb

[2.0][DDC-174] Fixed.

parent 25c95885
...@@ -20,4 +20,14 @@ class ORMException extends \Exception ...@@ -20,4 +20,14 @@ class ORMException extends \Exception
. " detected in collection '" . $assoc->sourceFieldName . "' during flush." . " detected in collection '" . $assoc->sourceFieldName . "' during flush."
. " Remove deleted entities from collections."); . " Remove deleted entities from collections.");
} }
public static function invalidEntityState($state)
{
return new self("Invalid entity state: $state.");
}
public static function detachedEntityCannotBeRemoved()
{
return new self("A detached entity can not be removed.");
}
} }
...@@ -854,13 +854,13 @@ class UnitOfWork implements PropertyChangedListener ...@@ -854,13 +854,13 @@ class UnitOfWork implements PropertyChangedListener
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if (isset($this->_entityUpdates[$oid])) { if (isset($this->_entityUpdates[$oid])) {
throw DoctrineException::dirtyObjectCannotBeRegisteredAsNew(); throw new \InvalidArgumentException("Dirty entity can not be scheduled for insertion.");
} }
if (isset($this->_entityDeletions[$oid])) { if (isset($this->_entityDeletions[$oid])) {
throw DoctrineException::removedObjectCannotBeRegisteredAsNew(); throw new \InvalidArgumentException("Removed entity can not be scheduled for insertion.");
} }
if (isset($this->_entityInsertions[$oid])) { if (isset($this->_entityInsertions[$oid])) {
throw DoctrineException::objectAlreadyRegisteredAsNew(); throw new \InvalidArgumentException("Entity can not be scheduled for insertion twice.");
} }
$this->_entityInsertions[$oid] = $entity; $this->_entityInsertions[$oid] = $entity;
...@@ -890,10 +890,10 @@ class UnitOfWork implements PropertyChangedListener ...@@ -890,10 +890,10 @@ class UnitOfWork implements PropertyChangedListener
{ {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if ( ! isset($this->_entityIdentifiers[$oid])) { if ( ! isset($this->_entityIdentifiers[$oid])) {
throw DoctrineException::entityWithoutIdentityCannotBeRegisteredAsDirty(); throw new \InvalidArgumentException("Entity has no identity.");
} }
if (isset($this->_entityDeletions[$oid])) { if (isset($this->_entityDeletions[$oid])) {
throw DoctrineException::removedObjectCannotBeRegisteredAsDirty(); throw new \InvalidArgumentException("Entity is removed.");
} }
if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) { if ( ! isset($this->_entityUpdates[$oid]) && ! isset($this->_entityInsertions[$oid])) {
...@@ -1009,7 +1009,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1009,7 +1009,7 @@ class UnitOfWork implements PropertyChangedListener
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = implode(' ', $this->_entityIdentifiers[spl_object_hash($entity)]); $idHash = implode(' ', $this->_entityIdentifiers[spl_object_hash($entity)]);
if ($idHash === '') { if ($idHash === '') {
throw DoctrineException::entityMustHaveIdentityToBeAddedToIdentityMap($entity); throw new \InvalidArgumentException("The given entity has no identity.");
} }
$className = $classMetadata->rootEntityName; $className = $classMetadata->rootEntityName;
if (isset($this->_identityMap[$className][$idHash])) { if (isset($this->_identityMap[$className][$idHash])) {
...@@ -1072,7 +1072,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1072,7 +1072,7 @@ class UnitOfWork implements PropertyChangedListener
$classMetadata = $this->_em->getClassMetadata(get_class($entity)); $classMetadata = $this->_em->getClassMetadata(get_class($entity));
$idHash = implode(' ', $this->_entityIdentifiers[$oid]); $idHash = implode(' ', $this->_entityIdentifiers[$oid]);
if ($idHash === '') { if ($idHash === '') {
throw DoctrineException::entityMustHaveIdentifyToBeRemovedFromIdentityMap($entity); throw new \InvalidArgumentException("The given entity has no identity.");
} }
$className = $classMetadata->rootEntityName; $className = $classMetadata->rootEntityName;
if (isset($this->_identityMap[$className][$idHash])) { if (isset($this->_identityMap[$className][$idHash])) {
...@@ -1212,8 +1212,8 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1212,8 +1212,8 @@ class UnitOfWork implements PropertyChangedListener
$this->scheduleForInsert($entity); $this->scheduleForInsert($entity);
break; break;
case self::STATE_DETACHED: case self::STATE_DETACHED:
throw DoctrineException::notImplemented("Behavior of save() for a detached entity " throw new \InvalidArgumentException(
. "is not yet defined."); "Behavior of save() for a detached entity is not yet defined.");
case self::STATE_REMOVED: case self::STATE_REMOVED:
// Entity becomes managed again // Entity becomes managed again
if ($this->isScheduledForDelete($entity)) { if ($this->isScheduledForDelete($entity)) {
...@@ -1224,7 +1224,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1224,7 +1224,7 @@ class UnitOfWork implements PropertyChangedListener
} }
break; break;
default: default:
throw DoctrineException::invalidEntityState($entityState); throw ORMException::invalidEntityState($entityState);
} }
$this->_cascadePersist($entity, $visited); $this->_cascadePersist($entity, $visited);
...@@ -1277,9 +1277,9 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1277,9 +1277,9 @@ class UnitOfWork implements PropertyChangedListener
$this->scheduleForDelete($entity); $this->scheduleForDelete($entity);
break; break;
case self::STATE_DETACHED: case self::STATE_DETACHED:
throw DoctrineException::detachedEntityCannotBeRemoved(); throw ORMException::detachedEntityCannotBeRemoved();
default: default:
throw DoctrineException::invalidEntityState($entityState); throw ORMException::invalidEntityState($entityState);
} }
$this->_cascadeRemove($entity, $visited); $this->_cascadeRemove($entity, $visited);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment