Doctrine\ODM\PHPCR\UnitOfWork::findVersionByName PHP Метод

findVersionByName() публичный Метод

См. также: DocumentManager::findVersionByName
public findVersionByName ( $className, $id, $versionName )
    public function findVersionByName($className, $id, $versionName)
    {
        $versionManager = $this->session->getWorkspace()->getVersionManager();
        try {
            $history = $versionManager->getVersionHistory($id);
        } catch (ItemNotFoundException $e) {
            // there is no document with $id
            return null;
        } catch (UnsupportedRepositoryOperationException $e) {
            throw new InvalidArgumentException("Document with id {$id} is not versionable", $e->getCode(), $e);
        }
        try {
            $version = $history->getVersion($versionName);
            $node = $version->getFrozenNode();
        } catch (RepositoryException $e) {
            throw new InvalidArgumentException("No version {$versionName} on document {$id}", $e->getCode(), $e);
        }
        $hints = array('versionName' => $versionName, 'ignoreHardReferenceNotFound' => true);
        $frozenDocument = $this->getOrCreateDocument($className, $node, $hints);
        $oid = spl_object_hash($frozenDocument);
        $this->documentHistory[$oid] = $history;
        $this->documentVersion[$oid] = $version;
        // Set the annotations
        $metadata = $this->dm->getClassMetadata(get_class($frozenDocument));
        if ($metadata->versionNameField) {
            $metadata->reflFields[$metadata->versionNameField]->setValue($frozenDocument, $versionName);
        }
        if ($metadata->versionCreatedField) {
            $metadata->reflFields[$metadata->versionCreatedField]->setValue($frozenDocument, $version->getCreated());
        }
        return $frozenDocument;
    }

Usage Example

Пример #1
0
 /**
  * Returns a read-only, detached document instance of the document at the
  * specified path with the specified version name.
  *
  * The id of the returned document representing this version is not the id
  * of the original document.
  *
  * @param null|string $className
  * @param string $id id of the document
  * @param string $versionName the version name as given by getLinearPredecessors
  *
  * @return the detached document or null if the document is not found
  *
  * @throws InvalidArgumentException if there is a document with $id but no
  *      version with $name
  * @throws UnsupportedRepositoryOperationException if the implementation
  *      does not support versioning
  */
 public function findVersionByName($className, $id, $versionName)
 {
     $this->errorIfClosed();
     return $this->unitOfWork->findVersionByName($className, $id, $versionName);
 }
UnitOfWork