public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = null) : ?object
    {
        if ($id === null) {
            return null;
        }

        /* TODO: What if the ID object has a field with the same name as the
         * class' mapped identifier field name?
         */
        if (is_array($id)) {
            [$identifierFieldName] = $this->class->getIdentifierFieldNames();

            if (isset($id[$identifierFieldName])) {
                $id = $id[$identifierFieldName];
            }
        }

        // Check identity map first
        $document = $this->uow->tryGetById($id, $this->class);
        if ($document) {
            if ($lockMode !== LockMode::NONE) {
                $this->dm->lock($document, $lockMode, $lockVersion);
            }

            return $document; // Hit!
        }

        $criteria = ['_id' => $id];

        if ($lockMode === LockMode::NONE) {
            return $this->getDocumentPersister()->load($criteria);
        }

        if ($lockMode === LockMode::OPTIMISTIC) {
            if (! $this->class->isVersioned) {
                throw LockException::notVersioned($this->documentName);
            }

            $document = $this->getDocumentPersister()->load($criteria);
            if ($document) {
                $this->uow->lock($document, $lockMode, $lockVersion);
            }

            return $document;
        }

        return $this->getDocumentPersister()->load($criteria, null, [], $lockMode);
    }
public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = null) : ?object
    {
        if ($id === null) {
            return null;
        }

        /* TODO: What if the ID object has a field with the same name as the
         * class' mapped identifier field name?
         */
        if (is_array($id)) {
            [$identifierFieldName] = $this->class->getIdentifierFieldNames();

            if (isset($id[$identifierFieldName])) {
                $id = $id[$identifierFieldName];
            }
        }

        // Check identity map first
        $document = $this->uow->tryGetById($id, $this->class);
        if ($document) {
            if ($lockMode !== LockMode::NONE) {
                $this->dm->lock($document, $lockMode, $lockVersion);
            }

            return $document; // Hit!
        }

        $criteria = ['_id' => $id];

        if ($lockMode === LockMode::NONE) {
            return $this->getDocumentPersister()->load($criteria);
        }

        if ($lockMode === LockMode::OPTIMISTIC) {
            if (! $this->class->isVersioned) {
                throw LockException::notVersioned($this->documentName);
            }

            $document = $this->getDocumentPersister()->load($criteria);
            if ($document) {
                $this->uow->lock($document, $lockMode, $lockVersion);
            }

            return $document;
        }

        return $this->getDocumentPersister()->load($criteria, null, [], $lockMode);
    }
public function find ( $ id , int $ lockMode = LockMode :: NONE , ? int $ lockVersion = null ) : ? object { if ( $ id === null ) { return null ; } /* TODO: What if the ID object has a field with the same name as the
         * class' mapped identifier field name?
         */ if ( is_array ( $ id ) ) { [ $ identifierFieldName ] = $ this -> class -> getIdentifierFieldNames ( ) ; if ( isset ( $ id [ $ identifierFieldName ] ) ) { $ id = $ id [ $ identifierFieldName ] ; } } // Check identity map first $ document = $ this -> uow -> tryGetById ( $ id , $ this -> class ) ; if ( $ document ) { if ( $ lockMode !== LockMode :: NONE ) { $ this -> dm -> lock ( $ document , $ lockMode , $ lockVersion ) ; } return $ document ; // Hit! } $ criteria = [ '_id' => $ id ] ; if ( $ lockMode === LockMode :: NONE ) { return $ this -> getDocumentPersister ( ) -> load ( $ criteria ) ; } if ( $ lockMode === LockMode :: OPTIMISTIC ) { if ( ! $ this -> class -> isVersioned ) { throw LockException :: notVersioned ( $ this -> documentName ) ; } $ document = $ this -> getDocumentPersister ( ) -> load ( $ criteria ) ; if ( $ document ) { $ this -> uow -> lock ( $ document , $ lockMode , $ lockVersion ) ; } return $ document ; } return $ this -> getDocumentPersister ( ) -> load ( $ criteria , null , [ ] , $ lockMode ) ; }
Finds a document matching the specified identifier. Optionally a lock mode and
expected version may be specified.

@param mixed $id Identifier.

@throws MappingException
@throws LockException
Finds a document matching the specified identifier . Optionally a lock mode and expected version may be specified .