Jackalope\ObjectManager::getNodeByIdentifier PHP Method

getNodeByIdentifier() public method

Get the node identified by an uuid.
See also: Session::getNodeByIdentifier()
public getNodeByIdentifier ( string $identifier, string $class = 'Node' ) : PHPCR\NodeInterface
$identifier string uuid
$class string optional class name for factory
return PHPCR\NodeInterface The specified Node. if not available, ItemNotFoundException is thrown
    public function getNodeByIdentifier($identifier, $class = 'Node')
    {
        if (empty($this->objectsByUuid[$identifier])) {
            $data = $this->transport->getNodeByIdentifier($identifier);
            $path = $data->{':jcr:path'};
            unset($data->{':jcr:path'});
            // TODO: $path is a backend path. we should inverse the getFetchPath operation here
            $node = $this->getNodeByPath($path, $class, $data);
            $this->objectsByUuid[$identifier] = $path;
            //only do this once the getNodeByPath has worked
            return $node;
        }
        return $this->getNodeByPath($this->objectsByUuid[$identifier], $class);
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function restore($removeExisting, $version, $absPath = null)
 {
     if ($this->objectManager->hasPendingChanges()) {
         throw new InvalidItemStateException('You may not call restore when there pending unsaved changes');
     }
     if (is_string($version)) {
         if (!is_string($absPath)) {
             throw new InvalidArgumentException('To restore version by version name you need to specify the path to the node you want to restore to this name');
         }
         $vh = $this->getVersionHistory($absPath);
         $version = $vh->getVersion($version);
         $versionPath = $version->getPath();
         $nodePath = $absPath;
     } elseif (is_array($version)) {
         // @codeCoverageIgnoreStart
         throw new NotImplementedException('TODO: implement restoring a list of versions');
         // @codeCoverageIgnoreEnd
     } elseif ($version instanceof VersionInterface && is_string($absPath)) {
         // @codeCoverageIgnoreStart
         throw new NotImplementedException('TODO: implement restoring a version to a specified path');
         // @codeCoverageIgnoreEnd
     } elseif ($version instanceof VersionInterface) {
         $versionPath = $version->getPath();
         $nodePath = $this->objectManager->getNodeByIdentifier($version->getContainingHistory()->getVersionableIdentifier())->getPath();
     } else {
         throw new InvalidArgumentException();
     }
     $this->objectManager->restore($removeExisting, $versionPath, $nodePath);
     $version->setCachedPredecessorsDirty();
     if ($history = $this->objectManager->getCachedNode(PathHelper::getParentPath($version->getPath()), 'Version\\VersionHistory')) {
         $history->notifyHistoryChanged();
     }
 }
All Usage Examples Of Jackalope\ObjectManager::getNodeByIdentifier