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

This is an optimization over getNode to get many nodes in one call. If the transport implementation does not optimize, it can just loop over the paths and call getNode repeatedly. If a transport can do it, it should also implement NodeTypeFilterInterface. For prefetch, there are two mechanisms: As with getNode, the stdClass structure may be recursive. Additionally, the transport is allowed to return additional entries that where not requested in the returned array. Jackalope takes care of only returning nodes that where actually requested by the client and caching the rest.
public getNodes ( array $paths ) : array
$paths array Absolute paths to the nodes.
Результат array keys are the absolute paths, values is the node data as associative array (decoded from json with associative = true)
 /**
  * {@inheritDoc}
  */
 public function getNodes($paths)
 {
     $this->logger->startCall(__FUNCTION__, func_get_args(), array('fetchDepth' => $this->transport->getFetchDepth()));
     $result = $this->transport->getNodes($paths);
     $this->logger->stopCall();
     return $result;
 }
Пример #2
0
 /**
  * Get multiple nodes identified by an absolute paths. Missing nodes are
  * ignored.
  *
  * Note paths that cannot be found will be ignored and missing from the
  * result.
  *
  * Uses the factory to create Node objects.
  *
  * @param array $paths Array containing the absolute paths of the nodes to
  *      fetch.
  * @param string $class The class of node to get. TODO: Is it sane to
  *      fetch data separately for Version and normal Node?
  *
  * @return ArrayIterator that contains all found NodeInterface
  *      instances keyed by their path
  *
  * @throws RepositoryException If the path is not absolute or not
  *      well-formed
  *
  * @see Session::getNodes()
  */
 public function getNodesByPath($paths, $class = 'Node')
 {
     $nodes = $fetchPaths = array();
     foreach ($paths as $absPath) {
         if (!empty($this->objectsByPath[$class][$absPath])) {
             // Return it from memory if we already have it
             $nodes[$absPath] = $this->objectsByPath[$class][$absPath];
         } else {
             $nodes[$absPath] = '';
             $fetchPaths[$absPath] = $this->getFetchPath($absPath, $class);
         }
     }
     if (!empty($fetchPaths)) {
         $data = $this->transport->getNodes($fetchPaths);
         $dataItems = array();
         foreach ($data as $fetchPath => $item) {
             $dataItems[$fetchPath] = $item;
         }
         foreach ($fetchPaths as $absPath => $fetchPath) {
             if (array_key_exists($fetchPath, $dataItems)) {
                 $nodes[$absPath] = $this->getNodeByPath($absPath, $class, $dataItems[$fetchPath]);
             } else {
                 unset($nodes[$absPath]);
             }
         }
     }
     return new ArrayIterator($nodes);
 }
Пример #3
0
 public function getNodesByPathAsArray($paths, $class = 'Node', $typeFilter = null)
 {
     if (is_string($typeFilter)) {
         $typeFilter = array($typeFilter);
     }
     $nodes = $fetchPaths = array();
     foreach ($paths as $absPath) {
         if (!empty($this->objectsByPath[$class][$absPath])) {
             // Return it from memory if we already have it and type is correct
             if ($typeFilter && !$this->matchNodeType($this->objectsByPath[$class][$absPath], $typeFilter)) {
                 // skip this node if it did not match a type filter
                 continue;
             }
             $nodes[$absPath] = $this->objectsByPath[$class][$absPath];
         } else {
             $nodes[$absPath] = '';
             $fetchPaths[$absPath] = $this->getFetchPath($absPath, $class);
         }
     }
     $userlandTypeFilter = false;
     if (!empty($fetchPaths)) {
         if ($typeFilter) {
             if ($this->transport instanceof NodeTypeFilterInterface) {
                 $data = $this->transport->getNodesFiltered($fetchPaths, $typeFilter);
             } else {
                 $data = $this->transport->getNodes($fetchPaths);
                 $userlandTypeFilter = true;
             }
         } else {
             $data = $this->transport->getNodes($fetchPaths);
         }
         $inversePaths = array_flip($fetchPaths);
         foreach ($data as $fetchPath => $item) {
             // only add this node to the list if it was actually requested.
             if (isset($inversePaths[$fetchPath])) {
                 // transform back to session paths from the fetch paths, in case of
                 // a pending move operation
                 $absPath = $inversePaths[$fetchPath];
                 $node = $this->getNodeByPath($absPath, $class, $item);
                 if ($userlandTypeFilter) {
                     if (null !== $typeFilter && !$this->matchNodeType($node, $typeFilter)) {
                         continue;
                     }
                 }
                 $nodes[$absPath] = $node;
                 unset($inversePaths[$fetchPath]);
             } else {
                 // this is either a prefetched node that was not requested
                 // or it falls through the type filter. cache it.
                 // first undo eventual move operation
                 $parent = $fetchPath;
                 $relPath = '';
                 while ($parent) {
                     if (isset($inversePaths[$parent])) {
                         break;
                     }
                     if ('/' == $parent) {
                         $parent = false;
                     } else {
                         $parent = PathHelper::getParentPath($parent);
                         $relPath = '/' . PathHelper::getNodeName($parent) . $relPath;
                     }
                 }
                 if ($parent) {
                     $this->getNodeByPath($parent . $relPath, $class, $item);
                 }
             }
         }
         // clean away the not found paths from the final result
         foreach ($inversePaths as $absPath) {
             unset($nodes[$absPath]);
         }
     }
     return $nodes;
 }