Jackalope\ObjectManager::getNodesByIdentifier PHP Method

getNodesByIdentifier() public method

Note UUIDs that are not found will be ignored. Also, duplicate IDs will be eliminated by nature of using the IDs as keys.
See also: Session::getNodesByIdentifier()
public getNodesByIdentifier ( array $identifiers, string $class = 'Node' ) : ArrayIterato\ArrayIterator | Node[]
$identifiers array UUIDs of nodes to retrieve.
$class string Optional class name for the factory.
return ArrayIterato\ArrayIterator | Node[] Iterator of the specified nodes keyed by their unique ids
    public function getNodesByIdentifier($identifiers, $class = 'Node')
    {
        $nodes = $fetchPaths = array();
        foreach ($identifiers as $uuid) {
            if (!empty($this->objectsByUuid[$uuid]) && !empty($this->objectsByPath[$class][$this->objectsByUuid[$uuid]])) {
                // Return it from memory if we already have it
                $nodes[$uuid] = $this->objectsByPath[$class][$this->objectsByUuid[$uuid]];
            } else {
                $fetchPaths[$uuid] = $uuid;
                $nodes[$uuid] = $uuid;
                // keep position
            }
        }
        if (!empty($fetchPaths)) {
            $data = $this->transport->getNodesByIdentifier($fetchPaths);
            foreach ($data as $absPath => $item) {
                // TODO: $absPath is the backend path. we should inverse the getFetchPath operation here
                // build the node from the received data
                $node = $this->getNodeByPath($absPath, $class, $item);
                $found[$node->getIdentifier()] = $node;
            }
            foreach ($nodes as $key => $node) {
                if (is_string($node)) {
                    if (isset($found[$node])) {
                        $nodes[$key] = $found[$node];
                    } else {
                        unset($nodes[$key]);
                    }
                }
            }
        }
        reset($nodes);
        return new ArrayIterator($nodes);
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getNodesByIdentifier($ids)
 {
     if (!is_array($ids) && !$ids instanceof \Traversable) {
         $hint = is_object($ids) ? get_class($ids) : gettype($ids);
         throw new InvalidArgumentException("Not a valid array or Traversable: {$hint}");
     }
     return $this->objectManager->getNodesByIdentifier($ids);
 }