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;
}