From ec160cede7fc094eda34aaa0ab679d506764368a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 24 May 2018 16:35:12 +0200 Subject: [PATCH] pass getNodeForPath requests to INodeByPath collections --- lib/DAV/Tree.php | 8 ++++++++ tests/Sabre/DAV/TreeTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/DAV/Tree.php b/lib/DAV/Tree.php index 48fd543375..65b4583ceb 100644 --- a/lib/DAV/Tree.php +++ b/lib/DAV/Tree.php @@ -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); diff --git a/tests/Sabre/DAV/TreeTest.php b/tests/Sabre/DAV/TreeTest.php index f798639676..c05258ddad 100644 --- a/tests/Sabre/DAV/TreeTest.php +++ b/tests/Sabre/DAV/TreeTest.php @@ -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 @@ -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'), + ]), + ]), ]) ); } @@ -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;