Пример #1
0
 /**
  * Create a proxy instance or return an existing document
  *
  * @param $targetId
  * @param $className
  *
  * @return object
  */
 private function createProxy($targetId, $className)
 {
     $document = $this->getDocumentById($targetId);
     // check if referenced document already exists
     if ($document) {
         return $document;
     }
     $proxyDocument = $this->dm->getProxyFactory()->getProxy($className, $targetId);
     // register the document under its own id
     $this->registerDocument($proxyDocument, $targetId);
     return $proxyDocument;
 }
Пример #2
0
 /**
  * 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
  */
 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, array($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;
 }