ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\Tree Class Reference

The tree object is responsible for basic tree operations. More...

+ Inheritance diagram for Sabre\DAV\Tree:
+ Collaboration diagram for Sabre\DAV\Tree:

Public Member Functions

 __construct (ICollection $rootNode)
 Creates the object. More...
 
 getNodeForPath ($path)
 Returns the INode object for the requested path. More...
 
 nodeExists ($path)
 This function allows you to check if a node exists. More...
 
 copy ($sourcePath, $destinationPath)
 Copies a file from path to another. More...
 
 move ($sourcePath, $destinationPath)
 Moves a file from one location to another. More...
 
 delete ($path)
 Deletes a node from the tree. More...
 
 getChildren ($path)
 Returns a list of childnodes for a given path. More...
 
 markDirty ($path)
 This method is called with every tree update. More...
 
 getMultipleNodes ($paths)
 This method tells the tree system to pre-fetch and cache a list of children of a single parent. More...
 

Protected Member Functions

 copyNode (INode $source, ICollection $destinationParent, $destinationName=null)
 copyNode More...
 

Protected Attributes

 $rootNode
 
 $cache = []
 

Detailed Description

The tree object is responsible for basic tree operations.

It allows for fetching nodes by path, facilitates deleting, copying and moving.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 17 of file Tree.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\DAV\Tree::__construct ( ICollection  $rootNode)

Creates the object.

This method expects the rootObject to be passed as a parameter

Parameters
ICollection$rootNode

Definition at line 41 of file Tree.php.

41 {
42
43 $this->rootNode = $rootNode;
44
45 }

References Sabre\DAV\Tree\$rootNode.

Member Function Documentation

◆ copy()

Sabre\DAV\Tree::copy (   $sourcePath,
  $destinationPath 
)

Copies a file from path to another.

Parameters
string$sourcePathThe source location
string$destinationPathThe full destination path
Returns
void

Definition at line 122 of file Tree.php.

122 {
123
124 $sourceNode = $this->getNodeForPath($sourcePath);
125
126 // grab the dirname and basename components
127 list($destinationDir, $destinationName) = URLUtil::splitPath($destinationPath);
128
129 $destinationParent = $this->getNodeForPath($destinationDir);
130 $this->copyNode($sourceNode, $destinationParent, $destinationName);
131
132 $this->markDirty($destinationDir);
133
134 }
getNodeForPath($path)
Returns the INode object for the requested path.
Definition: Tree.php:53
markDirty($path)
This method is called with every tree update.
Definition: Tree.php:226
copyNode(INode $source, ICollection $destinationParent, $destinationName=null)
copyNode
Definition: Tree.php:299
static splitPath($path)
Returns the 'dirname' and 'basename' for a path.
Definition: URLUtil.php:83

References Sabre\DAV\Tree\copyNode(), Sabre\DAV\Tree\getNodeForPath(), Sabre\DAV\Tree\markDirty(), and Sabre\HTTP\URLUtil\splitPath().

Referenced by Sabre\DAV\Tree\move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyNode()

Sabre\DAV\Tree::copyNode ( INode  $source,
ICollection  $destinationParent,
  $destinationName = null 
)
protected

copyNode

Parameters
INode$source
ICollection$destinationParent
string$destinationName
Returns
void

Definition at line 299 of file Tree.php.

299 {
300
301 if (!$destinationName) $destinationName = $source->getName();
302
303 if ($source instanceof IFile) {
304
305 $data = $source->get();
306
307 // If the body was a string, we need to convert it to a stream
308 if (is_string($data)) {
309 $stream = fopen('php://temp', 'r+');
310 fwrite($stream, $data);
311 rewind($stream);
312 $data = $stream;
313 }
314 $destinationParent->createFile($destinationName, $data);
315 $destination = $destinationParent->getChild($destinationName);
316
317 } elseif ($source instanceof ICollection) {
318
319 $destinationParent->createDirectory($destinationName);
320
321 $destination = $destinationParent->getChild($destinationName);
322 foreach ($source->getChildren() as $child) {
323
324 $this->copyNode($child, $destination);
325
326 }
327
328 }
329 if ($source instanceof IProperties && $destination instanceof IProperties) {
330
331 $props = $source->getProperties([]);
332 $propPatch = new PropPatch($props);
333 $destination->propPatch($propPatch);
334 $propPatch->commit();
335
336 }
337
338 }
$source
Definition: linkback.php:22
$destination
$stream
PHP stream implementation.
$data
Definition: bench.php:6

References $data, $destination, $source, GuzzleHttp\Psr7\$stream, Sabre\DAV\Tree\copyNode(), Sabre\DAV\ICollection\createDirectory(), Sabre\DAV\ICollection\createFile(), and Sabre\DAV\ICollection\getChild().

Referenced by Sabre\DAV\Tree\copy(), and Sabre\DAV\Tree\copyNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

Sabre\DAV\Tree::delete (   $path)

Deletes a node from the tree.

Parameters
string$path
Returns
void

Definition at line 176 of file Tree.php.

176 {
177
178 $node = $this->getNodeForPath($path);
179 $node->delete();
180
181 list($parent) = URLUtil::splitPath($path);
182 $this->markDirty($parent);
183
184 }
$path
Definition: aliased.php:25

References $path, Sabre\DAV\Tree\getNodeForPath(), Sabre\DAV\Tree\markDirty(), and Sabre\HTTP\URLUtil\splitPath().

+ Here is the call graph for this function:

◆ getChildren()

Sabre\DAV\Tree::getChildren (   $path)

Returns a list of childnodes for a given path.

Parameters
string$path
Returns
array

Definition at line 192 of file Tree.php.

192 {
193
194 $node = $this->getNodeForPath($path);
195 $children = $node->getChildren();
196 $basePath = trim($path, '/');
197 if ($basePath !== '') $basePath .= '/';
198
199 foreach ($children as $child) {
200
201 $this->cache[$basePath . $child->getName()] = $child;
202
203 }
204 return $children;
205
206 }

References $path, and Sabre\DAV\Tree\getNodeForPath().

+ Here is the call graph for this function:

◆ getMultipleNodes()

Sabre\DAV\Tree::getMultipleNodes (   $paths)

This method tells the tree system to pre-fetch and cache a list of children of a single parent.

There are a bunch of operations in the WebDAV stack that request many children (based on uris), and sometimes fetching many at once can optimize this.

This method returns an array with the found nodes. It's keys are the original paths. The result may be out of order.

Parameters
array$pathsList of nodes that must be fetched.
Returns
array

Definition at line 253 of file Tree.php.

253 {
254
255 // Finding common parents
256 $parents = [];
257 foreach ($paths as $path) {
258 list($parent, $node) = URLUtil::splitPath($path);
259 if (!isset($parents[$parent])) {
260 $parents[$parent] = [$node];
261 } else {
262 $parents[$parent][] = $node;
263 }
264 }
265
266 $result = [];
267
268 foreach ($parents as $parent => $children) {
269
270 $parentNode = $this->getNodeForPath($parent);
271 if ($parentNode instanceof IMultiGet) {
272 foreach ($parentNode->getMultipleChildren($children) as $childNode) {
273 $fullPath = $parent . '/' . $childNode->getName();
274 $result[$fullPath] = $childNode;
275 $this->cache[$fullPath] = $childNode;
276 }
277 } else {
278 foreach ($children as $child) {
279 $fullPath = $parent . '/' . $child;
280 $result[$fullPath] = $this->getNodeForPath($fullPath);
281 }
282 }
283
284 }
285
286 return $result;
287
288 }
$result
if($argc< 2) $paths
Definition: migrateto20.php:44

References $path, $paths, $result, Sabre\DAV\Tree\getNodeForPath(), and Sabre\HTTP\URLUtil\splitPath().

+ Here is the call graph for this function:

◆ getNodeForPath()

Sabre\DAV\Tree::getNodeForPath (   $path)

Returns the INode object for the requested path.

Parameters
string$path
Returns
INode

Definition at line 53 of file Tree.php.

53 {
54
55 $path = trim($path, '/');
56 if (isset($this->cache[$path])) return $this->cache[$path];
57
58 // Is it the root node?
59 if (!strlen($path)) {
60 return $this->rootNode;
61 }
62
63 // Attempting to fetch its parent
64 list($parentName, $baseName) = URLUtil::splitPath($path);
65
66 // If there was no parent, we must simply ask it from the root node.
67 if ($parentName === "") {
68 $node = $this->rootNode->getChild($baseName);
69 } else {
70 // Otherwise, we recursively grab the parent and ask him/her.
71 $parent = $this->getNodeForPath($parentName);
72
73 if (!($parent instanceof ICollection))
74 throw new Exception\NotFound('Could not find node at path: ' . $path);
75
76 $node = $parent->getChild($baseName);
77
78 }
79
80 $this->cache[$path] = $node;
81 return $node;
82
83 }

References $path, Sabre\DAV\Tree\$rootNode, Sabre\DAV\Tree\getNodeForPath(), and Sabre\HTTP\URLUtil\splitPath().

Referenced by Sabre\DAV\Tree\copy(), Sabre\DAV\Tree\delete(), Sabre\DAV\Tree\getChildren(), Sabre\DAV\Tree\getMultipleNodes(), Sabre\DAV\Tree\getNodeForPath(), Sabre\DAV\Tree\move(), and Sabre\DAV\Tree\nodeExists().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ markDirty()

Sabre\DAV\Tree::markDirty (   $path)

This method is called with every tree update.

Examples of tree updates are:

  • node deletions
  • node creations
  • copy
  • move
  • renaming nodes

If Tree classes implement a form of caching, this will allow them to make sure caches will be expired.

If a path is passed, it is assumed that the entire subtree is dirty

Parameters
string$path
Returns
void

Definition at line 226 of file Tree.php.

226 {
227
228 // We don't care enough about sub-paths
229 // flushing the entire cache
230 $path = trim($path, '/');
231 foreach ($this->cache as $nodePath => $node) {
232 if ($path === '' || $nodePath == $path || strpos($nodePath, $path . '/') === 0)
233 unset($this->cache[$nodePath]);
234
235 }
236
237 }

References $path.

Referenced by Sabre\DAV\Tree\copy(), Sabre\DAV\Tree\delete(), and Sabre\DAV\Tree\move().

+ Here is the caller graph for this function:

◆ move()

Sabre\DAV\Tree::move (   $sourcePath,
  $destinationPath 
)

Moves a file from one location to another.

Parameters
string$sourcePathThe path to the file which should be moved
string$destinationPathThe full destination path, so not just the destination parent node
Returns
int

Definition at line 143 of file Tree.php.

143 {
144
145 list($sourceDir) = URLUtil::splitPath($sourcePath);
146 list($destinationDir, $destinationName) = URLUtil::splitPath($destinationPath);
147
148 if ($sourceDir === $destinationDir) {
149 // If this is a 'local' rename, it means we can just trigger a rename.
150 $sourceNode = $this->getNodeForPath($sourcePath);
151 $sourceNode->setName($destinationName);
152 } else {
153 $newParentNode = $this->getNodeForPath($destinationDir);
154 $moveSuccess = false;
155 if ($newParentNode instanceof IMoveTarget) {
156 // The target collection may be able to handle the move
157 $sourceNode = $this->getNodeForPath($sourcePath);
158 $moveSuccess = $newParentNode->moveInto($destinationName, $sourcePath, $sourceNode);
159 }
160 if (!$moveSuccess) {
161 $this->copy($sourcePath, $destinationPath);
162 $this->getNodeForPath($sourcePath)->delete();
163 }
164 }
165 $this->markDirty($sourceDir);
166 $this->markDirty($destinationDir);
167
168 }
$sourceDir
Definition: buildPhar.php:15
copy($sourcePath, $destinationPath)
Copies a file from path to another.
Definition: Tree.php:122

References $sourceDir, Sabre\DAV\Tree\copy(), Sabre\DAV\Tree\getNodeForPath(), Sabre\DAV\Tree\markDirty(), and Sabre\HTTP\URLUtil\splitPath().

+ Here is the call graph for this function:

◆ nodeExists()

Sabre\DAV\Tree::nodeExists (   $path)

This function allows you to check if a node exists.

Implementors of this class should override this method to make it cheaper.

Parameters
string$path
Returns
bool

Definition at line 94 of file Tree.php.

94 {
95
96 try {
97
98 // The root always exists
99 if ($path === '') return true;
100
101 list($parent, $base) = URLUtil::splitPath($path);
102
103 $parentNode = $this->getNodeForPath($parent);
104 if (!$parentNode instanceof ICollection) return false;
105 return $parentNode->childExists($base);
106
107 } catch (Exception\NotFound $e) {
108
109 return false;
110
111 }
112
113 }
$base
Definition: index.php:4

References $base, $path, Sabre\DAV\Tree\getNodeForPath(), and Sabre\HTTP\URLUtil\splitPath().

+ Here is the call graph for this function:

Field Documentation

◆ $cache

Sabre\DAV\Tree::$cache = []
protected

Definition at line 32 of file Tree.php.

◆ $rootNode

Sabre\DAV\Tree::$rootNode
protected

Definition at line 24 of file Tree.php.

Referenced by Sabre\DAV\Tree\__construct(), and Sabre\DAV\Tree\getNodeForPath().


The documentation for this class was generated from the following file: