6 * This implementation of the Tree class makes use of the INode, IFile and ICollection API's
10 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11 * @author Evert Pot (http://www.rooftopsolutions.nl/)
12 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14 class Sabre_DAV_ObjectTree extends Sabre_DAV_Tree {
19 * @var Sabre_DAV_ICollection
24 * This is the node cache. Accessed nodes are stored here
28 protected $cache = array();
33 * This method expects the rootObject to be passed as a parameter
35 * @param Sabre_DAV_ICollection $rootNode
37 public function __construct(Sabre_DAV_ICollection $rootNode) {
39 $this->rootNode = $rootNode;
44 * Returns the INode object for the requested path
47 * @return Sabre_DAV_INode
49 public function getNodeForPath($path) {
51 $path = trim($path,'/');
52 if (isset($this->cache[$path])) return $this->cache[$path];
54 //if (!$path || $path=='.') return $this->rootNode;
55 $currentNode = $this->rootNode;
57 // We're splitting up the path variable into folder/subfolder components and traverse to the correct node..
58 foreach(explode('/',$path) as $pathPart) {
60 // If this part of the path is just a dot, it actually means we can skip it
61 if ($pathPart=='.' || $pathPart=='') continue;
63 if (!($currentNode instanceof Sabre_DAV_ICollection))
64 throw new Sabre_DAV_Exception_NotFound('Could not find node at path: ' . $path);
66 $currentNode = $currentNode->getChild($pathPart);
70 $this->cache[$path] = $currentNode;
76 * This function allows you to check if a node exists.
81 public function nodeExists($path) {
85 // The root always exists
86 if ($path==='') return true;
88 list($parent, $base) = Sabre_DAV_URLUtil::splitPath($path);
90 $parentNode = $this->getNodeForPath($parent);
91 if (!$parentNode instanceof Sabre_DAV_ICollection) return false;
92 return $parentNode->childExists($base);
94 } catch (Sabre_DAV_Exception_NotFound $e) {
103 * Returns a list of childnodes for a given path.
105 * @param string $path
108 public function getChildren($path) {
110 $node = $this->getNodeForPath($path);
111 $children = $node->getChildren();
112 foreach($children as $child) {
114 $this->cache[trim($path,'/') . '/' . $child->getName()] = $child;
122 * This method is called with every tree update
124 * Examples of tree updates are:
131 * If Tree classes implement a form of caching, this will allow
132 * them to make sure caches will be expired.
134 * If a path is passed, it is assumed that the entire subtree is dirty
136 * @param string $path
139 public function markDirty($path) {
141 // We don't care enough about sub-paths
142 // flushing the entire cache
143 $path = trim($path,'/');
144 foreach($this->cache as $nodePath=>$node) {
145 if ($nodePath == $path || strpos($nodePath,$path.'/')===0)
146 unset($this->cache[$nodePath]);