public function persistNew(ClassMetadata $class, $document, $overrideIdGenerator = null, $parent = null)
    {
        if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::prePersist)) {
            $this->eventListenersInvoker->invoke(
                $class,
                Event::prePersist,
                $document,
                new LifecycleEventArgs($document, $this->dm),
                $invoke
            );
        }

        $generator = $this->getIdGenerator($overrideIdGenerator ? $overrideIdGenerator : $class->idGenerator);
        $id = $generator->generate($document, $class, $this->dm, $parent);
        $this->registerDocument($document, $id);

        if (!$generator instanceof AssignedIdGenerator) {
            $class->setIdentifierValue($document, $id);
        }

        // If the UUID is mapped, generate it early resp. validate if already present.
        $uuidFieldName = $class->getUuidFieldName();
        if ($uuidFieldName) {
            $existingUuid = $class->getFieldValue($document, $uuidFieldName);
            if (!$existingUuid) {
                $class->setFieldValue($document, $uuidFieldName, $this->generateUuid());
            } elseif (!UUIDHelper::isUUID($existingUuid)) {
                throw RuntimeException::invalidUuid($id, ClassUtils::getClass($document), $existingUuid);
            }
        }
    }
public function persistNew(ClassMetadata $class, $document, $overrideIdGenerator = null, $parent = null)
    {
        if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::prePersist)) {
            $this->eventListenersInvoker->invoke(
                $class,
                Event::prePersist,
                $document,
                new LifecycleEventArgs($document, $this->dm),
                $invoke
            );
        }

        $generator = $this->getIdGenerator($overrideIdGenerator ? $overrideIdGenerator : $class->idGenerator);
        $id = $generator->generate($document, $class, $this->dm, $parent);
        $this->registerDocument($document, $id);

        if (!$generator instanceof AssignedIdGenerator) {
            $class->setIdentifierValue($document, $id);
        }

        // If the UUID is mapped, generate it early resp. validate if already present.
        $uuidFieldName = $class->getUuidFieldName();
        if ($uuidFieldName) {
            $existingUuid = $class->getFieldValue($document, $uuidFieldName);
            if (!$existingUuid) {
                $class->setFieldValue($document, $uuidFieldName, $this->generateUuid());
            } elseif (!UUIDHelper::isUUID($existingUuid)) {
                throw RuntimeException::invalidUuid($id, ClassUtils::getClass($document), $existingUuid);
            }
        }
    }
public function persistNew ( ClassMetadata $ class , $ document , $ overrideIdGenerator = null , $ parent = null ) { if ( $ invoke = $ this -> eventListenersInvoker -> getSubscribedSystems ( $ class , Event :: prePersist ) ) { $ this -> eventListenersInvoker -> invoke ( $ class , Event :: prePersist , $ document , new LifecycleEventArgs ( $ document , $ this -> dm ) , $ invoke ) ; } $ generator = $ this -> getIdGenerator ( $ overrideIdGenerator ? $ overrideIdGenerator : $ class -> idGenerator ) ; $ id = $ generator -> generate ( $ document , $ class , $ this -> dm , $ parent ) ; $ this -> registerDocument ( $ document , $ id ) ; if ( ! $ generator instanceof AssignedIdGenerator ) { $ class -> setIdentifierValue ( $ document , $ id ) ; } // If the UUID is mapped, generate it early resp. validate if already present. $ uuidFieldName = $ class -> getUuidFieldName ( ) ; if ( $ uuidFieldName ) { $ existingUuid = $ class -> getFieldValue ( $ document , $ uuidFieldName ) ; if ( ! $ existingUuid ) { $ class -> setFieldValue ( $ document , $ uuidFieldName , $ this -> generateUuid ( ) ) ; } elseif ( ! UUIDHelper :: isUUID ( $ existingUuid ) ) { throw RuntimeException :: invalidUuid ( $ id , ClassUtils :: getClass ( $ document ) , $ existingUuid ) ; } } }
Persist new document, marking it managed and generating the id and the node.

This method is either called through `DocumentManager#persist()` or during `DocumentManager#flush()`,
when persistence by reachability is applied.

@param ClassMetadata $class
@param object        $document
Persist new document marking it managed and generating the id and the node .