Пример #1
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;
 }