Skip to content

Commit

Permalink
pass getNodeForPath requests to INodeByPath collections
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Nov 9, 2023
1 parent d46777f commit ec160ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/DAV/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public function getNodeForPath($path)
throw new Exception\NotFound('Could not find node at path: '.$path);
}

if ($node instanceof INodeByPath) {
$targetNode = $node->getNodeForPath(implode('/', $parts));
if ($targetNode instanceof Node) {
$node = $targetNode;
break;
}
}

$part = array_shift($parts);
if ('' !== $part) {
$node = $node->getChild($part);
Expand Down
24 changes: 24 additions & 0 deletions tests/Sabre/DAV/TreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public function testGetMultipleNodes2()
self::assertArrayHasKey('multi/1', $result);
self::assertArrayHasKey('multi/2', $result);
}

function testGetSubTreeNode()
{
$tree = new TreeMock();
$this->assertInstanceOf(INode::class, $tree->getNodeForPath('subtree/sub/1'));
$this->assertInstanceOf(INode::class, $tree->getNodeForPath('subtree/2/3'));
}

}

class TreeMock extends Tree
Expand All @@ -126,6 +134,12 @@ public function __construct()
new TreeDirectoryTester('1', [
new TreeDirectoryTester('2'),
]),
new NodeByPathTester('subtree', [
new TreeFileTester('sub/1'),
new TreeDirectoryTester('2', [
new TreeFileTester('3'),
]),
]),
])
);
}
Expand Down Expand Up @@ -177,6 +191,16 @@ public function setName($name)
}
}

class NodeByPathTester extends SimpleCollection implements INodeByPath {
function getNodeForPath($path) {
if (isset($this->children[$path])) {
return $this->children[$path];
} else {
return null;
}
}
}

class TreeFileTester extends File implements IProperties
{
public $name;
Expand Down

0 comments on commit ec160ce

Please sign in to comment.