]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/FS/Directory.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / FS / Directory.php
1 <?php
2
3 /**
4  * Directory class
5  *
6  * @package Sabre
7  * @subpackage DAV
8  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9  * @author Evert Pot (http://www.rooftopsolutions.nl/)
10  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11  */
12 class Sabre_DAV_FS_Directory extends Sabre_DAV_FS_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
13
14     /**
15      * Creates a new file in the directory
16      *
17      * Data will either be supplied as a stream resource, or in certain cases
18      * as a string. Keep in mind that you may have to support either.
19      *
20      * After successful creation of the file, you may choose to return the ETag
21      * of the new file here.
22      *
23      * The returned ETag must be surrounded by double-quotes (The quotes should
24      * be part of the actual string).
25      *
26      * If you cannot accurately determine the ETag, you should not return it.
27      * If you don't store the file exactly as-is (you're transforming it
28      * somehow) you should also not return an ETag.
29      *
30      * This means that if a subsequent GET to this new file does not exactly
31      * return the same contents of what was submitted here, you are strongly
32      * recommended to omit the ETag.
33      *
34      * @param string $name Name of the file
35      * @param resource|string $data Initial payload
36      * @return null|string
37      */
38     public function createFile($name, $data = null) {
39
40         $newPath = $this->path . '/' . $name;
41         file_put_contents($newPath,$data);
42
43     }
44
45     /**
46      * Creates a new subdirectory
47      *
48      * @param string $name
49      * @return void
50      */
51     public function createDirectory($name) {
52
53         $newPath = $this->path . '/' . $name;
54         mkdir($newPath);
55
56     }
57
58     /**
59      * Returns a specific child node, referenced by its name
60      *
61      * This method must throw Sabre_DAV_Exception_NotFound if the node does not
62      * exist.
63      *
64      * @param string $name
65      * @throws Sabre_DAV_Exception_NotFound
66      * @return Sabre_DAV_INode
67      */
68     public function getChild($name) {
69
70         $path = $this->path . '/' . $name;
71
72         if (!file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
73
74         if (is_dir($path)) {
75
76             return new Sabre_DAV_FS_Directory($path);
77
78         } else {
79
80             return new Sabre_DAV_FS_File($path);
81
82         }
83
84     }
85
86     /**
87      * Returns an array with all the child nodes
88      *
89      * @return Sabre_DAV_INode[]
90      */
91     public function getChildren() {
92
93         $nodes = array();
94         foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node);
95         return $nodes;
96
97     }
98
99     /**
100      * Checks if a child exists.
101      *
102      * @param string $name
103      * @return bool
104      */
105     public function childExists($name) {
106
107         $path = $this->path . '/' . $name;
108         return file_exists($path);
109
110     }
111
112     /**
113      * Deletes all files in this directory, and then itself
114      *
115      * @return void
116      */
117     public function delete() {
118
119         foreach($this->getChildren() as $child) $child->delete();
120         rmdir($this->path);
121
122     }
123
124     /**
125      * Returns available diskspace information
126      *
127      * @return array
128      */
129     public function getQuotaInfo() {
130
131         return array(
132             disk_total_space($this->path)-disk_free_space($this->path),
133             disk_free_space($this->path)
134             );
135
136     }
137
138 }
139