Jackalope\ObjectManager::getFetchPath PHP Method

getFetchPath() protected method

Resolve the path through all pending operations and sanity check while doing this.
protected getFetchPath ( string $absPath, string $class ) : string
$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?
return string fetch path
    protected function getFetchPath($absPath, $class)
    {
        $absPath = PathHelper::normalizePath($absPath);
        if (!isset($this->objectsByPath[$class])) {
            $this->objectsByPath[$class] = array();
        }
        $op = end($this->operationsLog);
        while ($op) {
            if ($op instanceof MoveNodeOperation) {
                if ($absPath === $op->srcPath) {
                    throw new ItemNotFoundException("Path not found (moved in current session): {$absPath}");
                }
                if (strpos($absPath, $op->srcPath . '/') === 0) {
                    throw new ItemNotFoundException("Path not found (parent node {$op->srcPath} moved in current session): {$absPath}");
                }
                if (strpos($absPath, $op->dstPath . '/') === 0 || $absPath == $op->dstPath) {
                    $absPath = substr_replace($absPath, $op->srcPath, 0, strlen($op->dstPath));
                }
            } elseif ($op instanceof RemoveNodeOperation || $op instanceof RemovePropertyOperation) {
                if ($absPath === $op->srcPath) {
                    throw new ItemNotFoundException("Path not found (node deleted in current session): {$absPath}");
                }
                if (strpos($absPath, $op->srcPath . '/') === 0) {
                    throw new ItemNotFoundException("Path not found (parent node {$op->srcPath} deleted in current session): {$absPath}");
                }
            } elseif ($op instanceof AddNodeOperation) {
                if ($absPath === $op->srcPath) {
                    // we added this node at this point so no more sanity checks needed.
                    return $absPath;
                }
            }
            $op = prev($this->operationsLog);
        }
        return $absPath;
    }