Doctrine\ODM\MongoDB\UnitOfWork::doPersist PHP Method

doPersist() private method

This method is internally called during save() cascades as it tracks the already visited documents to prevent infinite recursions. NOTE: This method always considers documents that are not yet known to this UnitOfWork as NEW.
private doPersist ( object $document, array &$visited )
$document object The document to persist.
$visited array The already visited documents.
    private function doPersist($document, array &$visited)
    {
        $oid = spl_object_hash($document);
        if (isset($visited[$oid])) {
            return;
            // Prevent infinite recursion
        }
        $visited[$oid] = $document;
        // Mark visited
        $class = $this->dm->getClassMetadata(get_class($document));
        $documentState = $this->getDocumentState($document, self::STATE_NEW);
        switch ($documentState) {
            case self::STATE_MANAGED:
                // Nothing to do, except if policy is "deferred explicit"
                if ($class->isChangeTrackingDeferredExplicit()) {
                    $this->scheduleForDirtyCheck($document);
                }
                break;
            case self::STATE_NEW:
                $this->persistNew($class, $document);
                break;
            case self::STATE_REMOVED:
                // Document becomes managed again
                unset($this->documentDeletions[$oid]);
                $this->documentStates[$oid] = self::STATE_MANAGED;
                break;
            case self::STATE_DETACHED:
                throw new \InvalidArgumentException('Behavior of persist() for a detached document is not yet defined.');
            default:
                throw MongoDBException::invalidDocumentState($documentState);
        }
        $this->cascadePersist($document, $visited);
    }
UnitOfWork