source: pmb4.2/trunk/fuentes/pmb/admin/connecteurs/out/webdav/lib/Sabre/DAV/FS/Directory.php @ 815

Last change on this file since 815 was 815, checked in by jrpelegrina, 4 years ago

Initial release of pmb 4.2

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