/**
* Get the nodes identified by the given UUIDs.
*
* Note UUIDs that are not found will be ignored. Also, duplicate IDs
* will be eliminated by nature of using the IDs as keys.
*
* @param array $identifiers UUIDs of nodes to retrieve.
* @param string $class Optional class name for the factory.
*
* @return Node[] Iterator of the specified nodes keyed by their unique ids
*
* @throws RepositoryException if another error occurs.
*
* @see Session::getNodesByIdentifier()
*/
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);
}