private function doPersist($xmlEntity, array &$visited)
{
$oid = spl_object_hash($xmlEntity);
if (isset($visited[$oid])) {
return;
// Prevent infinite recursion
}
$visited[$oid] = $xmlEntity;
// Mark visited
$class = $this->xem->getClassMetadata(get_class($xmlEntity));
// We assume NEW, so DETACHED entities result in an exception on flush (constraint violation).
// If we would detect DETACHED here we would throw an exception anyway with the same
// consequences (not recoverable/programming error), so just assuming NEW here
// lets us avoid some database lookups for entities with natural identifiers.
$xmlEntityState = $this->getXmlEntityState($xmlEntity, self::STATE_NEW);
switch ($xmlEntityState) {
case self::STATE_MANAGED:
// Nothing to do, except if policy is "deferred explicit"
if ($class->isChangeTrackingDeferredExplicit()) {
$this->scheduleForDirtyCheck($xmlEntity);
}
break;
case self::STATE_NEW:
$this->persistNew($class, $xmlEntity);
break;
case self::STATE_REMOVED:
// Entity becomes managed again
unset($this->entityDeletions[$oid]);
$this->entityStates[$oid] = self::STATE_MANAGED;
break;
case self::STATE_DETACHED:
// Can actually not happen right now since we assume STATE_NEW.
throw new InvalidArgumentException("Detached entity passed to persist().");
default:
throw new UnexpectedValueException("Unexpected entity state: {$xmlEntityState}.");
}
// $this->cascadePersist($xmlEntity, $visited);
}