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
12 class Sabre_DAV_FS_Directory extends Sabre_DAV_FS_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
15 * Creates a new file in the directory
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.
20 * After successful creation of the file, you may choose to return the ETag
21 * of the new file here.
23 * The returned ETag must be surrounded by double-quotes (The quotes should
24 * be part of the actual string).
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.
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.
34 * @param string $name Name of the file
35 * @param resource|string $data Initial payload
38 public function createFile($name, $data = null) {
40 $newPath = $this->path . '/' . $name;
41 file_put_contents($newPath,$data);
46 * Creates a new subdirectory
51 public function createDirectory($name) {
53 $newPath = $this->path . '/' . $name;
59 * Returns a specific child node, referenced by its name
61 * This method must throw Sabre_DAV_Exception_NotFound if the node does not
65 * @throws Sabre_DAV_Exception_NotFound
66 * @return Sabre_DAV_INode
68 public function getChild($name) {
70 $path = $this->path . '/' . $name;
72 if (!file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
76 return new Sabre_DAV_FS_Directory($path);
80 return new Sabre_DAV_FS_File($path);
87 * Returns an array with all the child nodes
89 * @return Sabre_DAV_INode[]
91 public function getChildren() {
94 foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node);
100 * Checks if a child exists.
102 * @param string $name
105 public function childExists($name) {
107 $path = $this->path . '/' . $name;
108 return file_exists($path);
113 * Deletes all files in this directory, and then itself
117 public function delete() {
119 foreach($this->getChildren() as $child) $child->delete();
125 * Returns available diskspace information
129 public function getQuotaInfo() {
132 disk_total_space($this->path)-disk_free_space($this->path),
133 disk_free_space($this->path)