Jackalope\ObjectManager::getNodeByPath PHP Method

getNodeByPath() public method

To prevent unnecessary work to be done a cache is filled to only fetch nodes once. To reset a node with the data from the backend, use Node::refresh() Uses the factory to create a Node object.
See also: Session::getNode()
public getNodeByPath ( string $absPath, string $class = 'Node', object $object = null ) : PHPCR\NodeInterface
$absPath string The absolute path of the node to fetch.
$class string The class of node to get. TODO: Is it sane to fetch data separately for Version and normal Node?
$object object A (prefetched) object (de-serialized json) from the backend only to be used if we get child nodes in one backend call
return PHPCR\NodeInterface
    public function getNodeByPath($absPath, $class = 'Node', $object = null)
    {
        $absPath = PathHelper::normalizePath($absPath);
        if (!empty($this->objectsByPath[$class][$absPath])) {
            // Return it from memory if we already have it
            return $this->objectsByPath[$class][$absPath];
        }
        // do this even if we have item in cache, will throw error if path is deleted - sanity check
        $fetchPath = $this->getFetchPath($absPath, $class);
        if (!$object) {
            // this is the first request, get data from transport
            $object = $this->transport->getNode($fetchPath);
        }
        // recursively create nodes for pre-fetched children if fetchDepth was > 1
        foreach ($object as $name => $properties) {
            if (is_object($properties)) {
                $objVars = get_object_vars($properties);
                $countObjVars = count($objVars);
                // if there's more than one objectvar or just one and this isn't jcr:uuid,
                // then we assume this child was pre-fetched from the backend completely
                if ($countObjVars > 1 || $countObjVars == 1 && !isset($objVars['jcr:uuid'])) {
                    try {
                        $parentPath = '/' === $absPath ? '/' : $absPath . '/';
                        $this->getNodeByPath($parentPath . $name, $class, $properties);
                    } catch (ItemNotFoundException $ignore) {
                        // we get here if the item was deleted or moved locally. just ignore
                    }
                }
            }
        }
        /** @var $node NodeInterface */
        $node = $this->factory->get($class, array($object, $absPath, $this->session, $this));
        if ($uuid = $node->getIdentifier()) {
            // map even nodes that are not mix:referenceable, as long as they have a uuid
            $this->objectsByUuid[$uuid] = $absPath;
        }
        $this->objectsByPath[$class][$absPath] = $node;
        return $this->objectsByPath[$class][$absPath];
    }

Usage Example

Example #1
0
 public function current()
 {
     $path = $this->key();
     if (!isset($path)) {
         return null;
     }
     return $this->objectmanager->getNodeByPath($path);
 }
All Usage Examples Of Jackalope\ObjectManager::getNodeByPath