Doctrine\ODM\PHPCR\UnitOfWork::getOrCreateDocument PHP Method

getOrCreateDocument() public method

Supported hints are - refresh: reload the fields from the database if set - locale: use this locale instead of the one from the annotation or the default - fallback: whether to try other languages or throw a not found exception if the desired locale is not found. defaults to true if not set and locale is not given either. - prefetch: if set to false, do not attempt to prefetch related data. (This makes sense when the caller already did this beforehand.)
public getOrCreateDocument ( null | string $className, PHPCR\NodeInterface $node, array &$hints = [] ) : object
$className null | string
$node PHPCR\NodeInterface
$hints array
return object
    public function getOrCreateDocument($className, NodeInterface $node, array &$hints = array())
    {
        $documents = $this->getOrCreateDocuments($className, array($node), $hints);
        return array_shift($documents);
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  */
 public function findTranslation($className, $id, $locale, $fallback = true)
 {
     try {
         if (UUIDHelper::isUUID($id)) {
             try {
                 $id = $this->session->getNodeByIdentifier($id)->getPath();
             } catch (ItemNotFoundException $e) {
                 return null;
             }
         } elseif (strpos($id, '/') !== 0) {
             $id = '/' . $id;
         }
         $document = $this->unitOfWork->getDocumentById($id);
         if ($document) {
             $this->unitOfWork->validateClassName($document, $className);
             $class = $this->getClassMetadata(get_class($document));
             $this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback);
             return $document;
         }
         $node = $this->session->getNode($id);
     } catch (PathNotFoundException $e) {
         return null;
     }
     $hints = array('locale' => $locale, 'fallback' => $fallback);
     return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\UnitOfWork::getOrCreateDocument
UnitOfWork