@@ -27,150 +27,150 @@ |
||
27 | 27 | */ |
28 | 28 | class Plugin extends ServerPlugin |
29 | 29 | { |
30 | - /** |
|
31 | - * If you only want this plugin to store properties for a limited set of |
|
32 | - * paths, you can use a pathFilter to do this. |
|
33 | - * |
|
34 | - * The pathFilter should be a callable. The callable retrieves a path as |
|
35 | - * its argument, and should return true or false whether it allows |
|
36 | - * properties to be stored. |
|
37 | - * |
|
38 | - * @var callable |
|
39 | - */ |
|
40 | - public $pathFilter; |
|
30 | + /** |
|
31 | + * If you only want this plugin to store properties for a limited set of |
|
32 | + * paths, you can use a pathFilter to do this. |
|
33 | + * |
|
34 | + * The pathFilter should be a callable. The callable retrieves a path as |
|
35 | + * its argument, and should return true or false whether it allows |
|
36 | + * properties to be stored. |
|
37 | + * |
|
38 | + * @var callable |
|
39 | + */ |
|
40 | + public $pathFilter; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var Backend\BackendInterface |
|
44 | - */ |
|
45 | - public $backend; |
|
42 | + /** |
|
43 | + * @var Backend\BackendInterface |
|
44 | + */ |
|
45 | + public $backend; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Creates the plugin. |
|
49 | - */ |
|
50 | - public function __construct(Backend\BackendInterface $backend) |
|
51 | - { |
|
52 | - $this->backend = $backend; |
|
53 | - } |
|
47 | + /** |
|
48 | + * Creates the plugin. |
|
49 | + */ |
|
50 | + public function __construct(Backend\BackendInterface $backend) |
|
51 | + { |
|
52 | + $this->backend = $backend; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * This initializes the plugin. |
|
57 | - * |
|
58 | - * This function is called by Sabre\DAV\Server, after |
|
59 | - * addPlugin is called. |
|
60 | - * |
|
61 | - * This method should set up the required event subscriptions. |
|
62 | - */ |
|
63 | - public function initialize(Server $server) |
|
64 | - { |
|
65 | - $server->on('propFind', [$this, 'propFind'], 130); |
|
66 | - $server->on('propPatch', [$this, 'propPatch'], 300); |
|
67 | - $server->on('afterMove', [$this, 'afterMove']); |
|
68 | - $server->on('afterUnbind', [$this, 'afterUnbind']); |
|
69 | - } |
|
55 | + /** |
|
56 | + * This initializes the plugin. |
|
57 | + * |
|
58 | + * This function is called by Sabre\DAV\Server, after |
|
59 | + * addPlugin is called. |
|
60 | + * |
|
61 | + * This method should set up the required event subscriptions. |
|
62 | + */ |
|
63 | + public function initialize(Server $server) |
|
64 | + { |
|
65 | + $server->on('propFind', [$this, 'propFind'], 130); |
|
66 | + $server->on('propPatch', [$this, 'propPatch'], 300); |
|
67 | + $server->on('afterMove', [$this, 'afterMove']); |
|
68 | + $server->on('afterUnbind', [$this, 'afterUnbind']); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Called during PROPFIND operations. |
|
73 | - * |
|
74 | - * If there's any requested properties that don't have a value yet, this |
|
75 | - * plugin will look in the property storage backend to find them. |
|
76 | - */ |
|
77 | - public function propFind(PropFind $propFind, INode $node) |
|
78 | - { |
|
79 | - $path = $propFind->getPath(); |
|
80 | - $pathFilter = $this->pathFilter; |
|
81 | - if ($pathFilter && !$pathFilter($path)) { |
|
82 | - return; |
|
83 | - } |
|
84 | - $this->backend->propFind($propFind->getPath(), $propFind); |
|
85 | - } |
|
71 | + /** |
|
72 | + * Called during PROPFIND operations. |
|
73 | + * |
|
74 | + * If there's any requested properties that don't have a value yet, this |
|
75 | + * plugin will look in the property storage backend to find them. |
|
76 | + */ |
|
77 | + public function propFind(PropFind $propFind, INode $node) |
|
78 | + { |
|
79 | + $path = $propFind->getPath(); |
|
80 | + $pathFilter = $this->pathFilter; |
|
81 | + if ($pathFilter && !$pathFilter($path)) { |
|
82 | + return; |
|
83 | + } |
|
84 | + $this->backend->propFind($propFind->getPath(), $propFind); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Called during PROPPATCH operations. |
|
89 | - * |
|
90 | - * If there's any updated properties that haven't been stored, the |
|
91 | - * propertystorage backend can handle it. |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - */ |
|
95 | - public function propPatch($path, PropPatch $propPatch) |
|
96 | - { |
|
97 | - $pathFilter = $this->pathFilter; |
|
98 | - if ($pathFilter && !$pathFilter($path)) { |
|
99 | - return; |
|
100 | - } |
|
101 | - $this->backend->propPatch($path, $propPatch); |
|
102 | - } |
|
87 | + /** |
|
88 | + * Called during PROPPATCH operations. |
|
89 | + * |
|
90 | + * If there's any updated properties that haven't been stored, the |
|
91 | + * propertystorage backend can handle it. |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + */ |
|
95 | + public function propPatch($path, PropPatch $propPatch) |
|
96 | + { |
|
97 | + $pathFilter = $this->pathFilter; |
|
98 | + if ($pathFilter && !$pathFilter($path)) { |
|
99 | + return; |
|
100 | + } |
|
101 | + $this->backend->propPatch($path, $propPatch); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Called after a node is deleted. |
|
106 | - * |
|
107 | - * This allows the backend to clean up any properties still in the |
|
108 | - * database. |
|
109 | - * |
|
110 | - * @param string $path |
|
111 | - */ |
|
112 | - public function afterUnbind($path) |
|
113 | - { |
|
114 | - $pathFilter = $this->pathFilter; |
|
115 | - if ($pathFilter && !$pathFilter($path)) { |
|
116 | - return; |
|
117 | - } |
|
118 | - $this->backend->delete($path); |
|
119 | - } |
|
104 | + /** |
|
105 | + * Called after a node is deleted. |
|
106 | + * |
|
107 | + * This allows the backend to clean up any properties still in the |
|
108 | + * database. |
|
109 | + * |
|
110 | + * @param string $path |
|
111 | + */ |
|
112 | + public function afterUnbind($path) |
|
113 | + { |
|
114 | + $pathFilter = $this->pathFilter; |
|
115 | + if ($pathFilter && !$pathFilter($path)) { |
|
116 | + return; |
|
117 | + } |
|
118 | + $this->backend->delete($path); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Called after a node is moved. |
|
123 | - * |
|
124 | - * This allows the backend to move all the associated properties. |
|
125 | - * |
|
126 | - * @param string $source |
|
127 | - * @param string $destination |
|
128 | - */ |
|
129 | - public function afterMove($source, $destination) |
|
130 | - { |
|
131 | - $pathFilter = $this->pathFilter; |
|
132 | - if ($pathFilter && !$pathFilter($source)) { |
|
133 | - return; |
|
134 | - } |
|
135 | - // If the destination is filtered, afterUnbind will handle cleaning up |
|
136 | - // the properties. |
|
137 | - if ($pathFilter && !$pathFilter($destination)) { |
|
138 | - return; |
|
139 | - } |
|
121 | + /** |
|
122 | + * Called after a node is moved. |
|
123 | + * |
|
124 | + * This allows the backend to move all the associated properties. |
|
125 | + * |
|
126 | + * @param string $source |
|
127 | + * @param string $destination |
|
128 | + */ |
|
129 | + public function afterMove($source, $destination) |
|
130 | + { |
|
131 | + $pathFilter = $this->pathFilter; |
|
132 | + if ($pathFilter && !$pathFilter($source)) { |
|
133 | + return; |
|
134 | + } |
|
135 | + // If the destination is filtered, afterUnbind will handle cleaning up |
|
136 | + // the properties. |
|
137 | + if ($pathFilter && !$pathFilter($destination)) { |
|
138 | + return; |
|
139 | + } |
|
140 | 140 | |
141 | - $this->backend->move($source, $destination); |
|
142 | - } |
|
141 | + $this->backend->move($source, $destination); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Returns a plugin name. |
|
146 | - * |
|
147 | - * Using this name other plugins will be able to access other plugins |
|
148 | - * using \Sabre\DAV\Server::getPlugin |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function getPluginName() |
|
153 | - { |
|
154 | - return 'property-storage'; |
|
155 | - } |
|
144 | + /** |
|
145 | + * Returns a plugin name. |
|
146 | + * |
|
147 | + * Using this name other plugins will be able to access other plugins |
|
148 | + * using \Sabre\DAV\Server::getPlugin |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function getPluginName() |
|
153 | + { |
|
154 | + return 'property-storage'; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Returns a bunch of meta-data about the plugin. |
|
159 | - * |
|
160 | - * Providing this information is optional, and is mainly displayed by the |
|
161 | - * Browser plugin. |
|
162 | - * |
|
163 | - * The description key in the returned array may contain html and will not |
|
164 | - * be sanitized. |
|
165 | - * |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function getPluginInfo() |
|
169 | - { |
|
170 | - return [ |
|
171 | - 'name' => $this->getPluginName(), |
|
172 | - 'description' => 'This plugin allows any arbitrary WebDAV property to be set on any resource.', |
|
173 | - 'link' => 'http://sabre.io/dav/property-storage/', |
|
174 | - ]; |
|
175 | - } |
|
157 | + /** |
|
158 | + * Returns a bunch of meta-data about the plugin. |
|
159 | + * |
|
160 | + * Providing this information is optional, and is mainly displayed by the |
|
161 | + * Browser plugin. |
|
162 | + * |
|
163 | + * The description key in the returned array may contain html and will not |
|
164 | + * be sanitized. |
|
165 | + * |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function getPluginInfo() |
|
169 | + { |
|
170 | + return [ |
|
171 | + 'name' => $this->getPluginName(), |
|
172 | + 'description' => 'This plugin allows any arbitrary WebDAV property to be set on any resource.', |
|
173 | + 'link' => 'http://sabre.io/dav/property-storage/', |
|
174 | + ]; |
|
175 | + } |
|
176 | 176 | } |
@@ -19,57 +19,57 @@ |
||
19 | 19 | */ |
20 | 20 | interface BackendInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Fetches properties for a path. |
|
24 | - * |
|
25 | - * This method received a PropFind object, which contains all the |
|
26 | - * information about the properties that need to be fetched. |
|
27 | - * |
|
28 | - * Usually you would just want to call 'get404Properties' on this object, |
|
29 | - * as this will give you the _exact_ list of properties that need to be |
|
30 | - * fetched, and haven't yet. |
|
31 | - * |
|
32 | - * However, you can also support the 'allprops' property here. In that |
|
33 | - * case, you should check for $propFind->isAllProps(). |
|
34 | - * |
|
35 | - * @param string $path |
|
36 | - */ |
|
37 | - public function propFind($path, PropFind $propFind); |
|
22 | + /** |
|
23 | + * Fetches properties for a path. |
|
24 | + * |
|
25 | + * This method received a PropFind object, which contains all the |
|
26 | + * information about the properties that need to be fetched. |
|
27 | + * |
|
28 | + * Usually you would just want to call 'get404Properties' on this object, |
|
29 | + * as this will give you the _exact_ list of properties that need to be |
|
30 | + * fetched, and haven't yet. |
|
31 | + * |
|
32 | + * However, you can also support the 'allprops' property here. In that |
|
33 | + * case, you should check for $propFind->isAllProps(). |
|
34 | + * |
|
35 | + * @param string $path |
|
36 | + */ |
|
37 | + public function propFind($path, PropFind $propFind); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Updates properties for a path. |
|
41 | - * |
|
42 | - * This method received a PropPatch object, which contains all the |
|
43 | - * information about the update. |
|
44 | - * |
|
45 | - * Usually you would want to call 'handleRemaining' on this object, to get; |
|
46 | - * a list of all properties that need to be stored. |
|
47 | - * |
|
48 | - * @param string $path |
|
49 | - */ |
|
50 | - public function propPatch($path, PropPatch $propPatch); |
|
39 | + /** |
|
40 | + * Updates properties for a path. |
|
41 | + * |
|
42 | + * This method received a PropPatch object, which contains all the |
|
43 | + * information about the update. |
|
44 | + * |
|
45 | + * Usually you would want to call 'handleRemaining' on this object, to get; |
|
46 | + * a list of all properties that need to be stored. |
|
47 | + * |
|
48 | + * @param string $path |
|
49 | + */ |
|
50 | + public function propPatch($path, PropPatch $propPatch); |
|
51 | 51 | |
52 | - /** |
|
53 | - * This method is called after a node is deleted. |
|
54 | - * |
|
55 | - * This allows a backend to clean up all associated properties. |
|
56 | - * |
|
57 | - * The delete method will get called once for the deletion of an entire |
|
58 | - * tree. |
|
59 | - * |
|
60 | - * @param string $path |
|
61 | - */ |
|
62 | - public function delete($path); |
|
52 | + /** |
|
53 | + * This method is called after a node is deleted. |
|
54 | + * |
|
55 | + * This allows a backend to clean up all associated properties. |
|
56 | + * |
|
57 | + * The delete method will get called once for the deletion of an entire |
|
58 | + * tree. |
|
59 | + * |
|
60 | + * @param string $path |
|
61 | + */ |
|
62 | + public function delete($path); |
|
63 | 63 | |
64 | - /** |
|
65 | - * This method is called after a successful MOVE. |
|
66 | - * |
|
67 | - * This should be used to migrate all properties from one path to another. |
|
68 | - * Note that entire collections may be moved, so ensure that all properties |
|
69 | - * for children are also moved along. |
|
70 | - * |
|
71 | - * @param string $source |
|
72 | - * @param string $destination |
|
73 | - */ |
|
74 | - public function move($source, $destination); |
|
64 | + /** |
|
65 | + * This method is called after a successful MOVE. |
|
66 | + * |
|
67 | + * This should be used to migrate all properties from one path to another. |
|
68 | + * Note that entire collections may be moved, so ensure that all properties |
|
69 | + * for children are also moved along. |
|
70 | + * |
|
71 | + * @param string $source |
|
72 | + * @param string $destination |
|
73 | + */ |
|
74 | + public function move($source, $destination); |
|
75 | 75 | } |
@@ -22,203 +22,203 @@ |
||
22 | 22 | */ |
23 | 23 | class PDO implements BackendInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Value is stored as string. |
|
27 | - */ |
|
28 | - const VT_STRING = 1; |
|
29 | - |
|
30 | - /** |
|
31 | - * Value is stored as XML fragment. |
|
32 | - */ |
|
33 | - const VT_XML = 2; |
|
34 | - |
|
35 | - /** |
|
36 | - * Value is stored as a property object. |
|
37 | - */ |
|
38 | - const VT_OBJECT = 3; |
|
39 | - |
|
40 | - /** |
|
41 | - * PDO. |
|
42 | - * |
|
43 | - * @var \PDO |
|
44 | - */ |
|
45 | - protected $pdo; |
|
46 | - |
|
47 | - /** |
|
48 | - * PDO table name we'll be using. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $tableName = 'propertystorage'; |
|
53 | - |
|
54 | - /** |
|
55 | - * Creates the PDO property storage engine. |
|
56 | - */ |
|
57 | - public function __construct(\PDO $pdo) |
|
58 | - { |
|
59 | - $this->pdo = $pdo; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fetches properties for a path. |
|
64 | - * |
|
65 | - * This method received a PropFind object, which contains all the |
|
66 | - * information about the properties that need to be fetched. |
|
67 | - * |
|
68 | - * Usually you would just want to call 'get404Properties' on this object, |
|
69 | - * as this will give you the _exact_ list of properties that need to be |
|
70 | - * fetched, and haven't yet. |
|
71 | - * |
|
72 | - * However, you can also support the 'allprops' property here. In that |
|
73 | - * case, you should check for $propFind->isAllProps(). |
|
74 | - * |
|
75 | - * @param string $path |
|
76 | - */ |
|
77 | - public function propFind($path, PropFind $propFind) |
|
78 | - { |
|
79 | - if (!$propFind->isAllProps() && 0 === count($propFind->get404Properties())) { |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - $query = 'SELECT name, value, valuetype FROM '.$this->tableName.' WHERE path = ?'; |
|
84 | - $stmt = $this->pdo->prepare($query); |
|
85 | - $stmt->execute([$path]); |
|
86 | - |
|
87 | - while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
88 | - if ('resource' === gettype($row['value'])) { |
|
89 | - $row['value'] = stream_get_contents($row['value']); |
|
90 | - } |
|
91 | - switch ($row['valuetype']) { |
|
92 | - case null: |
|
93 | - case self::VT_STRING: |
|
94 | - $propFind->set($row['name'], $row['value']); |
|
95 | - break; |
|
96 | - case self::VT_XML: |
|
97 | - $propFind->set($row['name'], new Complex($row['value'])); |
|
98 | - break; |
|
99 | - case self::VT_OBJECT: |
|
100 | - $propFind->set($row['name'], unserialize($row['value'])); |
|
101 | - break; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Updates properties for a path. |
|
108 | - * |
|
109 | - * This method received a PropPatch object, which contains all the |
|
110 | - * information about the update. |
|
111 | - * |
|
112 | - * Usually you would want to call 'handleRemaining' on this object, to get; |
|
113 | - * a list of all properties that need to be stored. |
|
114 | - * |
|
115 | - * @param string $path |
|
116 | - */ |
|
117 | - public function propPatch($path, PropPatch $propPatch) |
|
118 | - { |
|
119 | - $propPatch->handleRemaining(function ($properties) use ($path) { |
|
120 | - if ('pgsql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
|
121 | - $updateSql = <<<SQL |
|
25 | + /** |
|
26 | + * Value is stored as string. |
|
27 | + */ |
|
28 | + const VT_STRING = 1; |
|
29 | + |
|
30 | + /** |
|
31 | + * Value is stored as XML fragment. |
|
32 | + */ |
|
33 | + const VT_XML = 2; |
|
34 | + |
|
35 | + /** |
|
36 | + * Value is stored as a property object. |
|
37 | + */ |
|
38 | + const VT_OBJECT = 3; |
|
39 | + |
|
40 | + /** |
|
41 | + * PDO. |
|
42 | + * |
|
43 | + * @var \PDO |
|
44 | + */ |
|
45 | + protected $pdo; |
|
46 | + |
|
47 | + /** |
|
48 | + * PDO table name we'll be using. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $tableName = 'propertystorage'; |
|
53 | + |
|
54 | + /** |
|
55 | + * Creates the PDO property storage engine. |
|
56 | + */ |
|
57 | + public function __construct(\PDO $pdo) |
|
58 | + { |
|
59 | + $this->pdo = $pdo; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fetches properties for a path. |
|
64 | + * |
|
65 | + * This method received a PropFind object, which contains all the |
|
66 | + * information about the properties that need to be fetched. |
|
67 | + * |
|
68 | + * Usually you would just want to call 'get404Properties' on this object, |
|
69 | + * as this will give you the _exact_ list of properties that need to be |
|
70 | + * fetched, and haven't yet. |
|
71 | + * |
|
72 | + * However, you can also support the 'allprops' property here. In that |
|
73 | + * case, you should check for $propFind->isAllProps(). |
|
74 | + * |
|
75 | + * @param string $path |
|
76 | + */ |
|
77 | + public function propFind($path, PropFind $propFind) |
|
78 | + { |
|
79 | + if (!$propFind->isAllProps() && 0 === count($propFind->get404Properties())) { |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + $query = 'SELECT name, value, valuetype FROM '.$this->tableName.' WHERE path = ?'; |
|
84 | + $stmt = $this->pdo->prepare($query); |
|
85 | + $stmt->execute([$path]); |
|
86 | + |
|
87 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
88 | + if ('resource' === gettype($row['value'])) { |
|
89 | + $row['value'] = stream_get_contents($row['value']); |
|
90 | + } |
|
91 | + switch ($row['valuetype']) { |
|
92 | + case null: |
|
93 | + case self::VT_STRING: |
|
94 | + $propFind->set($row['name'], $row['value']); |
|
95 | + break; |
|
96 | + case self::VT_XML: |
|
97 | + $propFind->set($row['name'], new Complex($row['value'])); |
|
98 | + break; |
|
99 | + case self::VT_OBJECT: |
|
100 | + $propFind->set($row['name'], unserialize($row['value'])); |
|
101 | + break; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Updates properties for a path. |
|
108 | + * |
|
109 | + * This method received a PropPatch object, which contains all the |
|
110 | + * information about the update. |
|
111 | + * |
|
112 | + * Usually you would want to call 'handleRemaining' on this object, to get; |
|
113 | + * a list of all properties that need to be stored. |
|
114 | + * |
|
115 | + * @param string $path |
|
116 | + */ |
|
117 | + public function propPatch($path, PropPatch $propPatch) |
|
118 | + { |
|
119 | + $propPatch->handleRemaining(function ($properties) use ($path) { |
|
120 | + if ('pgsql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
|
121 | + $updateSql = <<<SQL |
|
122 | 122 | INSERT INTO {$this->tableName} (path, name, valuetype, value) |
123 | 123 | VALUES (:path, :name, :valuetype, :value) |
124 | 124 | ON CONFLICT (path, name) |
125 | 125 | DO UPDATE SET valuetype = :valuetype, value = :value |
126 | 126 | SQL; |
127 | - } else { |
|
128 | - $updateSql = <<<SQL |
|
127 | + } else { |
|
128 | + $updateSql = <<<SQL |
|
129 | 129 | REPLACE INTO {$this->tableName} (path, name, valuetype, value) |
130 | 130 | VALUES (:path, :name, :valuetype, :value) |
131 | 131 | SQL; |
132 | - } |
|
133 | - |
|
134 | - $updateStmt = $this->pdo->prepare($updateSql); |
|
135 | - $deleteStmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE path = ? AND name = ?'); |
|
136 | - |
|
137 | - foreach ($properties as $name => $value) { |
|
138 | - if (!is_null($value)) { |
|
139 | - if (is_scalar($value)) { |
|
140 | - $valueType = self::VT_STRING; |
|
141 | - } elseif ($value instanceof Complex) { |
|
142 | - $valueType = self::VT_XML; |
|
143 | - $value = $value->getXml(); |
|
144 | - } else { |
|
145 | - $valueType = self::VT_OBJECT; |
|
146 | - $value = serialize($value); |
|
147 | - } |
|
148 | - |
|
149 | - $updateStmt->bindParam('path', $path, \PDO::PARAM_STR); |
|
150 | - $updateStmt->bindParam('name', $name, \PDO::PARAM_STR); |
|
151 | - $updateStmt->bindParam('valuetype', $valueType, \PDO::PARAM_INT); |
|
152 | - $updateStmt->bindParam('value', $value, \PDO::PARAM_LOB); |
|
153 | - |
|
154 | - $updateStmt->execute(); |
|
155 | - } else { |
|
156 | - $deleteStmt->execute([$path, $name]); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - return true; |
|
161 | - }); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * This method is called after a node is deleted. |
|
166 | - * |
|
167 | - * This allows a backend to clean up all associated properties. |
|
168 | - * |
|
169 | - * The delete method will get called once for the deletion of an entire |
|
170 | - * tree. |
|
171 | - * |
|
172 | - * @param string $path |
|
173 | - */ |
|
174 | - public function delete($path) |
|
175 | - { |
|
176 | - $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName." WHERE path = ? OR path LIKE ? ESCAPE '='"); |
|
177 | - $childPath = strtr( |
|
178 | - $path, |
|
179 | - [ |
|
180 | - '=' => '==', |
|
181 | - '%' => '=%', |
|
182 | - '_' => '=_', |
|
183 | - ] |
|
184 | - ).'/%'; |
|
185 | - |
|
186 | - $stmt->execute([$path, $childPath]); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * This method is called after a successful MOVE. |
|
191 | - * |
|
192 | - * This should be used to migrate all properties from one path to another. |
|
193 | - * Note that entire collections may be moved, so ensure that all properties |
|
194 | - * for children are also moved along. |
|
195 | - * |
|
196 | - * @param string $source |
|
197 | - * @param string $destination |
|
198 | - */ |
|
199 | - public function move($source, $destination) |
|
200 | - { |
|
201 | - // I don't know a way to write this all in a single sql query that's |
|
202 | - // also compatible across db engines, so we're letting PHP do all the |
|
203 | - // updates. Much slower, but it should still be pretty fast in most |
|
204 | - // cases. |
|
205 | - $select = $this->pdo->prepare('SELECT id, path FROM '.$this->tableName.' WHERE path = ? OR path LIKE ?'); |
|
206 | - $select->execute([$source, $source.'/%']); |
|
207 | - |
|
208 | - $update = $this->pdo->prepare('UPDATE '.$this->tableName.' SET path = ? WHERE id = ?'); |
|
209 | - while ($row = $select->fetch(\PDO::FETCH_ASSOC)) { |
|
210 | - // Sanity check. SQL may select too many records, such as records |
|
211 | - // with different cases. |
|
212 | - if ($row['path'] !== $source && 0 !== strpos($row['path'], $source.'/')) { |
|
213 | - continue; |
|
214 | - } |
|
215 | - |
|
216 | - $trailingPart = substr($row['path'], strlen($source) + 1); |
|
217 | - $newPath = $destination; |
|
218 | - if ($trailingPart) { |
|
219 | - $newPath .= '/'.$trailingPart; |
|
220 | - } |
|
221 | - $update->execute([$newPath, $row['id']]); |
|
222 | - } |
|
223 | - } |
|
132 | + } |
|
133 | + |
|
134 | + $updateStmt = $this->pdo->prepare($updateSql); |
|
135 | + $deleteStmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE path = ? AND name = ?'); |
|
136 | + |
|
137 | + foreach ($properties as $name => $value) { |
|
138 | + if (!is_null($value)) { |
|
139 | + if (is_scalar($value)) { |
|
140 | + $valueType = self::VT_STRING; |
|
141 | + } elseif ($value instanceof Complex) { |
|
142 | + $valueType = self::VT_XML; |
|
143 | + $value = $value->getXml(); |
|
144 | + } else { |
|
145 | + $valueType = self::VT_OBJECT; |
|
146 | + $value = serialize($value); |
|
147 | + } |
|
148 | + |
|
149 | + $updateStmt->bindParam('path', $path, \PDO::PARAM_STR); |
|
150 | + $updateStmt->bindParam('name', $name, \PDO::PARAM_STR); |
|
151 | + $updateStmt->bindParam('valuetype', $valueType, \PDO::PARAM_INT); |
|
152 | + $updateStmt->bindParam('value', $value, \PDO::PARAM_LOB); |
|
153 | + |
|
154 | + $updateStmt->execute(); |
|
155 | + } else { |
|
156 | + $deleteStmt->execute([$path, $name]); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + return true; |
|
161 | + }); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * This method is called after a node is deleted. |
|
166 | + * |
|
167 | + * This allows a backend to clean up all associated properties. |
|
168 | + * |
|
169 | + * The delete method will get called once for the deletion of an entire |
|
170 | + * tree. |
|
171 | + * |
|
172 | + * @param string $path |
|
173 | + */ |
|
174 | + public function delete($path) |
|
175 | + { |
|
176 | + $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName." WHERE path = ? OR path LIKE ? ESCAPE '='"); |
|
177 | + $childPath = strtr( |
|
178 | + $path, |
|
179 | + [ |
|
180 | + '=' => '==', |
|
181 | + '%' => '=%', |
|
182 | + '_' => '=_', |
|
183 | + ] |
|
184 | + ).'/%'; |
|
185 | + |
|
186 | + $stmt->execute([$path, $childPath]); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * This method is called after a successful MOVE. |
|
191 | + * |
|
192 | + * This should be used to migrate all properties from one path to another. |
|
193 | + * Note that entire collections may be moved, so ensure that all properties |
|
194 | + * for children are also moved along. |
|
195 | + * |
|
196 | + * @param string $source |
|
197 | + * @param string $destination |
|
198 | + */ |
|
199 | + public function move($source, $destination) |
|
200 | + { |
|
201 | + // I don't know a way to write this all in a single sql query that's |
|
202 | + // also compatible across db engines, so we're letting PHP do all the |
|
203 | + // updates. Much slower, but it should still be pretty fast in most |
|
204 | + // cases. |
|
205 | + $select = $this->pdo->prepare('SELECT id, path FROM '.$this->tableName.' WHERE path = ? OR path LIKE ?'); |
|
206 | + $select->execute([$source, $source.'/%']); |
|
207 | + |
|
208 | + $update = $this->pdo->prepare('UPDATE '.$this->tableName.' SET path = ? WHERE id = ?'); |
|
209 | + while ($row = $select->fetch(\PDO::FETCH_ASSOC)) { |
|
210 | + // Sanity check. SQL may select too many records, such as records |
|
211 | + // with different cases. |
|
212 | + if ($row['path'] !== $source && 0 !== strpos($row['path'], $source.'/')) { |
|
213 | + continue; |
|
214 | + } |
|
215 | + |
|
216 | + $trailingPart = substr($row['path'], strlen($source) + 1); |
|
217 | + $newPath = $destination; |
|
218 | + if ($trailingPart) { |
|
219 | + $newPath .= '/'.$trailingPart; |
|
220 | + } |
|
221 | + $update->execute([$newPath, $row['id']]); |
|
222 | + } |
|
223 | + } |
|
224 | 224 | } |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | public function propPatch($path, PropPatch $propPatch) |
118 | 118 | { |
119 | - $propPatch->handleRemaining(function ($properties) use ($path) { |
|
119 | + $propPatch->handleRemaining(function($properties) use ($path) { |
|
120 | 120 | if ('pgsql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
121 | 121 | $updateSql = <<<SQL |
122 | 122 | INSERT INTO {$this->tableName} (path, name, valuetype, value) |
@@ -123,12 +123,12 @@ |
||
123 | 123 | VALUES (:path, :name, :valuetype, :value) |
124 | 124 | ON CONFLICT (path, name) |
125 | 125 | DO UPDATE SET valuetype = :valuetype, value = :value |
126 | -SQL; |
|
126 | +sql; |
|
127 | 127 | } else { |
128 | 128 | $updateSql = <<<SQL |
129 | 129 | REPLACE INTO {$this->tableName} (path, name, valuetype, value) |
130 | 130 | VALUES (:path, :name, :valuetype, :value) |
131 | -SQL; |
|
131 | +sql; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $updateStmt = $this->pdo->prepare($updateSql); |
@@ -15,91 +15,91 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class ServerPlugin |
17 | 17 | { |
18 | - /** |
|
19 | - * This initializes the plugin. |
|
20 | - * |
|
21 | - * This function is called by Sabre\DAV\Server, after |
|
22 | - * addPlugin is called. |
|
23 | - * |
|
24 | - * This method should set up the required event subscriptions. |
|
25 | - */ |
|
26 | - abstract public function initialize(Server $server); |
|
18 | + /** |
|
19 | + * This initializes the plugin. |
|
20 | + * |
|
21 | + * This function is called by Sabre\DAV\Server, after |
|
22 | + * addPlugin is called. |
|
23 | + * |
|
24 | + * This method should set up the required event subscriptions. |
|
25 | + */ |
|
26 | + abstract public function initialize(Server $server); |
|
27 | 27 | |
28 | - /** |
|
29 | - * This method should return a list of server-features. |
|
30 | - * |
|
31 | - * This is for example 'versioning' and is added to the DAV: header |
|
32 | - * in an OPTIONS response. |
|
33 | - * |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - public function getFeatures() |
|
37 | - { |
|
38 | - return []; |
|
39 | - } |
|
28 | + /** |
|
29 | + * This method should return a list of server-features. |
|
30 | + * |
|
31 | + * This is for example 'versioning' and is added to the DAV: header |
|
32 | + * in an OPTIONS response. |
|
33 | + * |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + public function getFeatures() |
|
37 | + { |
|
38 | + return []; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Use this method to tell the server this plugin defines additional |
|
43 | - * HTTP methods. |
|
44 | - * |
|
45 | - * This method is passed a uri. It should only return HTTP methods that are |
|
46 | - * available for the specified uri. |
|
47 | - * |
|
48 | - * @param string $path |
|
49 | - * |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function getHTTPMethods($path) |
|
53 | - { |
|
54 | - return []; |
|
55 | - } |
|
41 | + /** |
|
42 | + * Use this method to tell the server this plugin defines additional |
|
43 | + * HTTP methods. |
|
44 | + * |
|
45 | + * This method is passed a uri. It should only return HTTP methods that are |
|
46 | + * available for the specified uri. |
|
47 | + * |
|
48 | + * @param string $path |
|
49 | + * |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function getHTTPMethods($path) |
|
53 | + { |
|
54 | + return []; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns a plugin name. |
|
59 | - * |
|
60 | - * Using this name other plugins will be able to access other plugins |
|
61 | - * using \Sabre\DAV\Server::getPlugin |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getPluginName() |
|
66 | - { |
|
67 | - return get_class($this); |
|
68 | - } |
|
57 | + /** |
|
58 | + * Returns a plugin name. |
|
59 | + * |
|
60 | + * Using this name other plugins will be able to access other plugins |
|
61 | + * using \Sabre\DAV\Server::getPlugin |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getPluginName() |
|
66 | + { |
|
67 | + return get_class($this); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns a list of reports this plugin supports. |
|
72 | - * |
|
73 | - * This will be used in the {DAV:}supported-report-set property. |
|
74 | - * Note that you still need to subscribe to the 'report' event to actually |
|
75 | - * implement them |
|
76 | - * |
|
77 | - * @param string $uri |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getSupportedReportSet($uri) |
|
82 | - { |
|
83 | - return []; |
|
84 | - } |
|
70 | + /** |
|
71 | + * Returns a list of reports this plugin supports. |
|
72 | + * |
|
73 | + * This will be used in the {DAV:}supported-report-set property. |
|
74 | + * Note that you still need to subscribe to the 'report' event to actually |
|
75 | + * implement them |
|
76 | + * |
|
77 | + * @param string $uri |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getSupportedReportSet($uri) |
|
82 | + { |
|
83 | + return []; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Returns a bunch of meta-data about the plugin. |
|
88 | - * |
|
89 | - * Providing this information is optional, and is mainly displayed by the |
|
90 | - * Browser plugin. |
|
91 | - * |
|
92 | - * The description key in the returned array may contain html and will not |
|
93 | - * be sanitized. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function getPluginInfo() |
|
98 | - { |
|
99 | - return [ |
|
100 | - 'name' => $this->getPluginName(), |
|
101 | - 'description' => null, |
|
102 | - 'link' => null, |
|
103 | - ]; |
|
104 | - } |
|
86 | + /** |
|
87 | + * Returns a bunch of meta-data about the plugin. |
|
88 | + * |
|
89 | + * Providing this information is optional, and is mainly displayed by the |
|
90 | + * Browser plugin. |
|
91 | + * |
|
92 | + * The description key in the returned array may contain html and will not |
|
93 | + * be sanitized. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function getPluginInfo() |
|
98 | + { |
|
99 | + return [ |
|
100 | + 'name' => $this->getPluginName(), |
|
101 | + 'description' => null, |
|
102 | + 'link' => null, |
|
103 | + ]; |
|
104 | + } |
|
105 | 105 | } |
@@ -16,28 +16,28 @@ |
||
16 | 16 | */ |
17 | 17 | interface IExtendedCollection extends ICollection |
18 | 18 | { |
19 | - /** |
|
20 | - * Creates a new collection. |
|
21 | - * |
|
22 | - * This method will receive a MkCol object with all the information about |
|
23 | - * the new collection that's being created. |
|
24 | - * |
|
25 | - * The MkCol object contains information about the resourceType of the new |
|
26 | - * collection. If you don't support the specified resourceType, you should |
|
27 | - * throw Exception\InvalidResourceType. |
|
28 | - * |
|
29 | - * The object also contains a list of WebDAV properties for the new |
|
30 | - * collection. |
|
31 | - * |
|
32 | - * You should call the handle() method on this object to specify exactly |
|
33 | - * which properties you are storing. This allows the system to figure out |
|
34 | - * exactly which properties you didn't store, which in turn allows other |
|
35 | - * plugins (such as the propertystorage plugin) to handle storing the |
|
36 | - * property for you. |
|
37 | - * |
|
38 | - * @param string $name |
|
39 | - * |
|
40 | - * @throws Exception\InvalidResourceType |
|
41 | - */ |
|
42 | - public function createExtendedCollection($name, MkCol $mkCol); |
|
19 | + /** |
|
20 | + * Creates a new collection. |
|
21 | + * |
|
22 | + * This method will receive a MkCol object with all the information about |
|
23 | + * the new collection that's being created. |
|
24 | + * |
|
25 | + * The MkCol object contains information about the resourceType of the new |
|
26 | + * collection. If you don't support the specified resourceType, you should |
|
27 | + * throw Exception\InvalidResourceType. |
|
28 | + * |
|
29 | + * The object also contains a list of WebDAV properties for the new |
|
30 | + * collection. |
|
31 | + * |
|
32 | + * You should call the handle() method on this object to specify exactly |
|
33 | + * which properties you are storing. This allows the system to figure out |
|
34 | + * exactly which properties you didn't store, which in turn allows other |
|
35 | + * plugins (such as the propertystorage plugin) to handle storing the |
|
36 | + * property for you. |
|
37 | + * |
|
38 | + * @param string $name |
|
39 | + * |
|
40 | + * @throws Exception\InvalidResourceType |
|
41 | + */ |
|
42 | + public function createExtendedCollection($name, MkCol $mkCol); |
|
43 | 43 | } |
@@ -17,102 +17,102 @@ |
||
17 | 17 | */ |
18 | 18 | class SimpleFile extends File |
19 | 19 | { |
20 | - /** |
|
21 | - * File contents. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $contents = []; |
|
20 | + /** |
|
21 | + * File contents. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $contents = []; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Name of this resource. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $name; |
|
27 | + /** |
|
28 | + * Name of this resource. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $name; |
|
33 | 33 | |
34 | - /** |
|
35 | - * A mimetype, such as 'text/plain' or 'text/html'. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $mimeType; |
|
34 | + /** |
|
35 | + * A mimetype, such as 'text/plain' or 'text/html'. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $mimeType; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Creates this node. |
|
43 | - * |
|
44 | - * The name of the node must be passed, as well as the contents of the |
|
45 | - * file. |
|
46 | - * |
|
47 | - * @param string $name |
|
48 | - * @param string $contents |
|
49 | - * @param string|null $mimeType |
|
50 | - */ |
|
51 | - public function __construct($name, $contents, $mimeType = null) |
|
52 | - { |
|
53 | - $this->name = $name; |
|
54 | - $this->contents = $contents; |
|
55 | - $this->mimeType = $mimeType; |
|
56 | - } |
|
41 | + /** |
|
42 | + * Creates this node. |
|
43 | + * |
|
44 | + * The name of the node must be passed, as well as the contents of the |
|
45 | + * file. |
|
46 | + * |
|
47 | + * @param string $name |
|
48 | + * @param string $contents |
|
49 | + * @param string|null $mimeType |
|
50 | + */ |
|
51 | + public function __construct($name, $contents, $mimeType = null) |
|
52 | + { |
|
53 | + $this->name = $name; |
|
54 | + $this->contents = $contents; |
|
55 | + $this->mimeType = $mimeType; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Returns the node name for this file. |
|
60 | - * |
|
61 | - * This name is used to construct the url. |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getName() |
|
66 | - { |
|
67 | - return $this->name; |
|
68 | - } |
|
58 | + /** |
|
59 | + * Returns the node name for this file. |
|
60 | + * |
|
61 | + * This name is used to construct the url. |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getName() |
|
66 | + { |
|
67 | + return $this->name; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns the data. |
|
72 | - * |
|
73 | - * This method may either return a string or a readable stream resource |
|
74 | - * |
|
75 | - * @return mixed |
|
76 | - */ |
|
77 | - public function get() |
|
78 | - { |
|
79 | - return $this->contents; |
|
80 | - } |
|
70 | + /** |
|
71 | + * Returns the data. |
|
72 | + * |
|
73 | + * This method may either return a string or a readable stream resource |
|
74 | + * |
|
75 | + * @return mixed |
|
76 | + */ |
|
77 | + public function get() |
|
78 | + { |
|
79 | + return $this->contents; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns the size of the file, in bytes. |
|
84 | - * |
|
85 | - * @return int |
|
86 | - */ |
|
87 | - public function getSize() |
|
88 | - { |
|
89 | - return strlen($this->contents); |
|
90 | - } |
|
82 | + /** |
|
83 | + * Returns the size of the file, in bytes. |
|
84 | + * |
|
85 | + * @return int |
|
86 | + */ |
|
87 | + public function getSize() |
|
88 | + { |
|
89 | + return strlen($this->contents); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the ETag for a file. |
|
94 | - * |
|
95 | - * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
96 | - * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
97 | - * |
|
98 | - * Return null if the ETag can not effectively be determined |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function getETag() |
|
103 | - { |
|
104 | - return '"'.sha1($this->contents).'"'; |
|
105 | - } |
|
92 | + /** |
|
93 | + * Returns the ETag for a file. |
|
94 | + * |
|
95 | + * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
96 | + * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
97 | + * |
|
98 | + * Return null if the ETag can not effectively be determined |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function getETag() |
|
103 | + { |
|
104 | + return '"'.sha1($this->contents).'"'; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Returns the mime-type for a file. |
|
109 | - * |
|
110 | - * If null is returned, we'll assume application/octet-stream |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function getContentType() |
|
115 | - { |
|
116 | - return $this->mimeType; |
|
117 | - } |
|
107 | + /** |
|
108 | + * Returns the mime-type for a file. |
|
109 | + * |
|
110 | + * If null is returned, we'll assume application/octet-stream |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function getContentType() |
|
115 | + { |
|
116 | + return $this->mimeType; |
|
117 | + } |
|
118 | 118 | } |
@@ -17,11 +17,11 @@ |
||
17 | 17 | */ |
18 | 18 | interface IQuota extends ICollection |
19 | 19 | { |
20 | - /** |
|
21 | - * Returns the quota information. |
|
22 | - * |
|
23 | - * This method MUST return an array with 2 values, the first being the total used space, |
|
24 | - * the second the available space (in bytes) |
|
25 | - */ |
|
26 | - public function getQuotaInfo(); |
|
20 | + /** |
|
21 | + * Returns the quota information. |
|
22 | + * |
|
23 | + * This method MUST return an array with 2 values, the first being the total used space, |
|
24 | + * the second the available space (in bytes) |
|
25 | + */ |
|
26 | + public function getQuotaInfo(); |
|
27 | 27 | } |
@@ -15,133 +15,133 @@ |
||
15 | 15 | */ |
16 | 16 | class Directory extends Node implements DAV\ICollection, DAV\IQuota |
17 | 17 | { |
18 | - /** |
|
19 | - * Creates a new file in the directory. |
|
20 | - * |
|
21 | - * Data will either be supplied as a stream resource, or in certain cases |
|
22 | - * as a string. Keep in mind that you may have to support either. |
|
23 | - * |
|
24 | - * After successful creation of the file, you may choose to return the ETag |
|
25 | - * of the new file here. |
|
26 | - * |
|
27 | - * The returned ETag must be surrounded by double-quotes (The quotes should |
|
28 | - * be part of the actual string). |
|
29 | - * |
|
30 | - * If you cannot accurately determine the ETag, you should not return it. |
|
31 | - * If you don't store the file exactly as-is (you're transforming it |
|
32 | - * somehow) you should also not return an ETag. |
|
33 | - * |
|
34 | - * This means that if a subsequent GET to this new file does not exactly |
|
35 | - * return the same contents of what was submitted here, you are strongly |
|
36 | - * recommended to omit the ETag. |
|
37 | - * |
|
38 | - * @param string $name Name of the file |
|
39 | - * @param resource|string $data Initial payload |
|
40 | - * |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public function createFile($name, $data = null) |
|
44 | - { |
|
45 | - $newPath = $this->path.'/'.$name; |
|
46 | - file_put_contents($newPath, $data); |
|
47 | - clearstatcache(true, $newPath); |
|
48 | - } |
|
18 | + /** |
|
19 | + * Creates a new file in the directory. |
|
20 | + * |
|
21 | + * Data will either be supplied as a stream resource, or in certain cases |
|
22 | + * as a string. Keep in mind that you may have to support either. |
|
23 | + * |
|
24 | + * After successful creation of the file, you may choose to return the ETag |
|
25 | + * of the new file here. |
|
26 | + * |
|
27 | + * The returned ETag must be surrounded by double-quotes (The quotes should |
|
28 | + * be part of the actual string). |
|
29 | + * |
|
30 | + * If you cannot accurately determine the ETag, you should not return it. |
|
31 | + * If you don't store the file exactly as-is (you're transforming it |
|
32 | + * somehow) you should also not return an ETag. |
|
33 | + * |
|
34 | + * This means that if a subsequent GET to this new file does not exactly |
|
35 | + * return the same contents of what was submitted here, you are strongly |
|
36 | + * recommended to omit the ETag. |
|
37 | + * |
|
38 | + * @param string $name Name of the file |
|
39 | + * @param resource|string $data Initial payload |
|
40 | + * |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public function createFile($name, $data = null) |
|
44 | + { |
|
45 | + $newPath = $this->path.'/'.$name; |
|
46 | + file_put_contents($newPath, $data); |
|
47 | + clearstatcache(true, $newPath); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Creates a new subdirectory. |
|
52 | - * |
|
53 | - * @param string $name |
|
54 | - */ |
|
55 | - public function createDirectory($name) |
|
56 | - { |
|
57 | - $newPath = $this->path.'/'.$name; |
|
58 | - mkdir($newPath); |
|
59 | - clearstatcache(true, $newPath); |
|
60 | - } |
|
50 | + /** |
|
51 | + * Creates a new subdirectory. |
|
52 | + * |
|
53 | + * @param string $name |
|
54 | + */ |
|
55 | + public function createDirectory($name) |
|
56 | + { |
|
57 | + $newPath = $this->path.'/'.$name; |
|
58 | + mkdir($newPath); |
|
59 | + clearstatcache(true, $newPath); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns a specific child node, referenced by its name. |
|
64 | - * |
|
65 | - * This method must throw DAV\Exception\NotFound if the node does not |
|
66 | - * exist. |
|
67 | - * |
|
68 | - * @param string $name |
|
69 | - * |
|
70 | - * @throws DAV\Exception\NotFound |
|
71 | - * |
|
72 | - * @return DAV\INode |
|
73 | - */ |
|
74 | - public function getChild($name) |
|
75 | - { |
|
76 | - $path = $this->path.'/'.$name; |
|
62 | + /** |
|
63 | + * Returns a specific child node, referenced by its name. |
|
64 | + * |
|
65 | + * This method must throw DAV\Exception\NotFound if the node does not |
|
66 | + * exist. |
|
67 | + * |
|
68 | + * @param string $name |
|
69 | + * |
|
70 | + * @throws DAV\Exception\NotFound |
|
71 | + * |
|
72 | + * @return DAV\INode |
|
73 | + */ |
|
74 | + public function getChild($name) |
|
75 | + { |
|
76 | + $path = $this->path.'/'.$name; |
|
77 | 77 | |
78 | - if (!file_exists($path)) { |
|
79 | - throw new DAV\Exception\NotFound('File with name '.$path.' could not be located'); |
|
80 | - } |
|
81 | - if (is_dir($path)) { |
|
82 | - return new self($path); |
|
83 | - } else { |
|
84 | - return new File($path); |
|
85 | - } |
|
86 | - } |
|
78 | + if (!file_exists($path)) { |
|
79 | + throw new DAV\Exception\NotFound('File with name '.$path.' could not be located'); |
|
80 | + } |
|
81 | + if (is_dir($path)) { |
|
82 | + return new self($path); |
|
83 | + } else { |
|
84 | + return new File($path); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Returns an array with all the child nodes. |
|
90 | - * |
|
91 | - * @return DAV\INode[] |
|
92 | - */ |
|
93 | - public function getChildren() |
|
94 | - { |
|
95 | - $nodes = []; |
|
96 | - $iterator = new \FilesystemIterator( |
|
97 | - $this->path, |
|
98 | - \FilesystemIterator::CURRENT_AS_SELF |
|
99 | - | \FilesystemIterator::SKIP_DOTS |
|
100 | - ); |
|
101 | - foreach ($iterator as $entry) { |
|
102 | - $nodes[] = $this->getChild($entry->getFilename()); |
|
103 | - } |
|
88 | + /** |
|
89 | + * Returns an array with all the child nodes. |
|
90 | + * |
|
91 | + * @return DAV\INode[] |
|
92 | + */ |
|
93 | + public function getChildren() |
|
94 | + { |
|
95 | + $nodes = []; |
|
96 | + $iterator = new \FilesystemIterator( |
|
97 | + $this->path, |
|
98 | + \FilesystemIterator::CURRENT_AS_SELF |
|
99 | + | \FilesystemIterator::SKIP_DOTS |
|
100 | + ); |
|
101 | + foreach ($iterator as $entry) { |
|
102 | + $nodes[] = $this->getChild($entry->getFilename()); |
|
103 | + } |
|
104 | 104 | |
105 | - return $nodes; |
|
106 | - } |
|
105 | + return $nodes; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Checks if a child exists. |
|
110 | - * |
|
111 | - * @param string $name |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function childExists($name) |
|
116 | - { |
|
117 | - $path = $this->path.'/'.$name; |
|
108 | + /** |
|
109 | + * Checks if a child exists. |
|
110 | + * |
|
111 | + * @param string $name |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function childExists($name) |
|
116 | + { |
|
117 | + $path = $this->path.'/'.$name; |
|
118 | 118 | |
119 | - return file_exists($path); |
|
120 | - } |
|
119 | + return file_exists($path); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Deletes all files in this directory, and then itself. |
|
124 | - */ |
|
125 | - public function delete() |
|
126 | - { |
|
127 | - foreach ($this->getChildren() as $child) { |
|
128 | - $child->delete(); |
|
129 | - } |
|
130 | - rmdir($this->path); |
|
131 | - } |
|
122 | + /** |
|
123 | + * Deletes all files in this directory, and then itself. |
|
124 | + */ |
|
125 | + public function delete() |
|
126 | + { |
|
127 | + foreach ($this->getChildren() as $child) { |
|
128 | + $child->delete(); |
|
129 | + } |
|
130 | + rmdir($this->path); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Returns available diskspace information. |
|
135 | - * |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function getQuotaInfo() |
|
139 | - { |
|
140 | - $absolute = realpath($this->path); |
|
133 | + /** |
|
134 | + * Returns available diskspace information. |
|
135 | + * |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function getQuotaInfo() |
|
139 | + { |
|
140 | + $absolute = realpath($this->path); |
|
141 | 141 | |
142 | - return [ |
|
143 | - disk_total_space($absolute) - disk_free_space($absolute), |
|
144 | - disk_free_space($absolute), |
|
145 | - ]; |
|
146 | - } |
|
142 | + return [ |
|
143 | + disk_total_space($absolute) - disk_free_space($absolute), |
|
144 | + disk_free_space($absolute), |
|
145 | + ]; |
|
146 | + } |
|
147 | 147 | } |
@@ -15,73 +15,73 @@ |
||
15 | 15 | */ |
16 | 16 | class File extends Node implements DAV\IFile |
17 | 17 | { |
18 | - /** |
|
19 | - * Updates the data. |
|
20 | - * |
|
21 | - * @param resource $data |
|
22 | - */ |
|
23 | - public function put($data) |
|
24 | - { |
|
25 | - file_put_contents($this->path, $data); |
|
26 | - clearstatcache(true, $this->path); |
|
27 | - } |
|
18 | + /** |
|
19 | + * Updates the data. |
|
20 | + * |
|
21 | + * @param resource $data |
|
22 | + */ |
|
23 | + public function put($data) |
|
24 | + { |
|
25 | + file_put_contents($this->path, $data); |
|
26 | + clearstatcache(true, $this->path); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Returns the data. |
|
31 | - * |
|
32 | - * @return resource |
|
33 | - */ |
|
34 | - public function get() |
|
35 | - { |
|
36 | - return fopen($this->path, 'r'); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Returns the data. |
|
31 | + * |
|
32 | + * @return resource |
|
33 | + */ |
|
34 | + public function get() |
|
35 | + { |
|
36 | + return fopen($this->path, 'r'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Delete the current file. |
|
41 | - */ |
|
42 | - public function delete() |
|
43 | - { |
|
44 | - unlink($this->path); |
|
45 | - } |
|
39 | + /** |
|
40 | + * Delete the current file. |
|
41 | + */ |
|
42 | + public function delete() |
|
43 | + { |
|
44 | + unlink($this->path); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the size of the node, in bytes. |
|
49 | - * |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function getSize() |
|
53 | - { |
|
54 | - return filesize($this->path); |
|
55 | - } |
|
47 | + /** |
|
48 | + * Returns the size of the node, in bytes. |
|
49 | + * |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function getSize() |
|
53 | + { |
|
54 | + return filesize($this->path); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns the ETag for a file. |
|
59 | - * |
|
60 | - * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
61 | - * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
62 | - * |
|
63 | - * Return null if the ETag can not effectively be determined |
|
64 | - * |
|
65 | - * @return mixed |
|
66 | - */ |
|
67 | - public function getETag() |
|
68 | - { |
|
69 | - return '"'.sha1( |
|
70 | - fileinode($this->path). |
|
71 | - filesize($this->path). |
|
72 | - filemtime($this->path) |
|
73 | - ).'"'; |
|
74 | - } |
|
57 | + /** |
|
58 | + * Returns the ETag for a file. |
|
59 | + * |
|
60 | + * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
61 | + * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
62 | + * |
|
63 | + * Return null if the ETag can not effectively be determined |
|
64 | + * |
|
65 | + * @return mixed |
|
66 | + */ |
|
67 | + public function getETag() |
|
68 | + { |
|
69 | + return '"'.sha1( |
|
70 | + fileinode($this->path). |
|
71 | + filesize($this->path). |
|
72 | + filemtime($this->path) |
|
73 | + ).'"'; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Returns the mime-type for a file. |
|
78 | - * |
|
79 | - * If null is returned, we'll assume application/octet-stream |
|
80 | - * |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public function getContentType() |
|
84 | - { |
|
85 | - return null; |
|
86 | - } |
|
76 | + /** |
|
77 | + * Returns the mime-type for a file. |
|
78 | + * |
|
79 | + * If null is returned, we'll assume application/octet-stream |
|
80 | + * |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public function getContentType() |
|
84 | + { |
|
85 | + return null; |
|
86 | + } |
|
87 | 87 | } |