1<?php
2
3namespace Sabre\DAVACL\FS;
4
5use Sabre\DAV\FSExt\Directory as BaseCollection;
6use Sabre\DAVACL\IACL;
7use Sabre\DAV\Exception\Forbidden;
8use Sabre\DAV\Exception\NotFound;
9
10/**
11 * This is an ACL-enabled collection.
12 *
13 * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
14 * @author Evert Pot (http://evertpot.com/)
15 * @license http://sabre.io/license/ Modified BSD License
16 */
17class Collection extends BaseCollection implements IACL {
18
19    /**
20     * A list of ACL rules.
21     *
22     * @var array
23     */
24    protected $acl;
25
26    /**
27     * Owner uri, or null for no owner.
28     *
29     * @var string|null
30     */
31    protected $owner;
32
33    /**
34     * Constructor
35     *
36     * @param string $path on-disk path.
37     * @param array $acl ACL rules.
38     * @param string|null $owner principal owner string.
39     */
40    function __construct($path, array $acl, $owner = null) {
41
42        parent::__construct($path);
43        $this->acl = $acl;
44        $this->owner = $owner;
45
46    }
47
48    /**
49     * Returns a specific child node, referenced by its name
50     *
51     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
52     * exist.
53     *
54     * @param string $name
55     * @throws DAV\Exception\NotFound
56     * @return DAV\INode
57     */
58    function getChild($name) {
59
60        $path = $this->path . '/' . $name;
61
62        if (!file_exists($path)) throw new NotFound('File could not be located');
63        if ($name == '.' || $name == '..') throw new Forbidden('Permission denied to . and ..');
64
65        if (is_dir($path)) {
66
67            return new self($path, $this->acl, $this->owner);
68
69        } else {
70
71            return new File($path, $this->acl, $this->owner);
72
73        }
74
75    }
76
77    /**
78     * Returns the owner principal
79     *
80     * This must be a url to a principal, or null if there's no owner
81     *
82     * @return string|null
83     */
84    function getOwner() {
85
86        return $this->owner;
87
88    }
89
90    /**
91     * Returns a group principal
92     *
93     * This must be a url to a principal, or null if there's no owner
94     *
95     * @return string|null
96     */
97    function getGroup() {
98
99        return null;
100
101    }
102
103    /**
104     * Returns a list of ACE's for this node.
105     *
106     * Each ACE has the following properties:
107     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
108     *     currently the only supported privileges
109     *   * 'principal', a url to the principal who owns the node
110     *   * 'protected' (optional), indicating that this ACE is not allowed to
111     *      be updated.
112     *
113     * @return array
114     */
115    function getACL() {
116
117        return $this->acl;
118
119    }
120
121    /**
122     * Updates the ACL
123     *
124     * This method will receive a list of new ACE's as an array argument.
125     *
126     * @param array $acl
127     * @return void
128     */
129    function setACL(array $acl) {
130
131        throw new Forbidden('Setting ACL is not allowed here');
132
133    }
134
135    /**
136     * Returns the list of supported privileges for this node.
137     *
138     * The returned data structure is a list of nested privileges.
139     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
140     * standard structure.
141     *
142     * If null is returned from this method, the default privilege set is used,
143     * which is fine for most common usecases.
144     *
145     * @return array|null
146     */
147    function getSupportedPrivilegeSet() {
148
149        return null;
150
151    }
152
153}
154