public function getOrCreateProxy($targetId, $className, $locale = null)
    {
        $document = $this->getDocumentById($targetId);

        // check if referenced document already exists
        if ($document) {
            $metadata = $this->dm->getClassMetadata($className);
            if ($locale && $locale !== $this->getCurrentLocale($document, $metadata)) {
                $this->doLoadTranslation($document, $metadata, $locale, true);
            }

            return $document;
        }

        $metadata = $this->dm->getClassMetadata($className);
        $proxyDocument = $this->dm->getProxyFactory()->getProxy($className, [$metadata->identifier => $targetId]);

        // register the document under its own id
        $this->registerDocument($proxyDocument, $targetId);

        if ($locale) {
            $this->setLocale($proxyDocument, $this->dm->getClassMetadata($className), $locale);
        }

        return $proxyDocument;
    }
public function getOrCreateProxy($targetId, $className, $locale = null)
    {
        $document = $this->getDocumentById($targetId);

        // check if referenced document already exists
        if ($document) {
            $metadata = $this->dm->getClassMetadata($className);
            if ($locale && $locale !== $this->getCurrentLocale($document, $metadata)) {
                $this->doLoadTranslation($document, $metadata, $locale, true);
            }

            return $document;
        }

        $metadata = $this->dm->getClassMetadata($className);
        $proxyDocument = $this->dm->getProxyFactory()->getProxy($className, [$metadata->identifier => $targetId]);

        // register the document under its own id
        $this->registerDocument($proxyDocument, $targetId);

        if ($locale) {
            $this->setLocale($proxyDocument, $this->dm->getClassMetadata($className), $locale);
        }

        return $proxyDocument;
    }
public function getOrCreateProxy ( $ targetId , $ className , $ locale = null ) { $ document = $ this -> getDocumentById ( $ targetId ) ; // check if referenced document already exists if ( $ document ) { $ metadata = $ this -> dm -> getClassMetadata ( $ className ) ; if ( $ locale && $ locale !== $ this -> getCurrentLocale ( $ document , $ metadata ) ) { $ this -> doLoadTranslation ( $ document , $ metadata , $ locale , true ) ; } return $ document ; } $ metadata = $ this -> dm -> getClassMetadata ( $ className ) ; $ proxyDocument = $ this -> dm -> getProxyFactory ( ) -> getProxy ( $ className , [ $ metadata -> identifier => $ targetId ] ) ; // register the document under its own id $ this -> registerDocument ( $ proxyDocument , $ targetId ) ; if ( $ locale ) { $ this -> setLocale ( $ proxyDocument , $ this -> dm -> getClassMetadata ( $ className ) , $ locale ) ; } return $ proxyDocument ; }
Get the existing document or proxy for this id of this class, or create
a new one.

@param string $targetId
@param string $className
@param string $locale

@return object
Get the existing document or proxy for this id of this class or create a new one .