@@ -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 | } |
@@ -19,78 +19,78 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class Node implements INode |
21 | 21 | { |
22 | - /** |
|
23 | - * The path to the current node. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $path; |
|
22 | + /** |
|
23 | + * The path to the current node. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $path; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The overridden name of the node. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $overrideName; |
|
29 | + /** |
|
30 | + * The overridden name of the node. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $overrideName; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Sets up the node, expects a full path name. |
|
38 | - * |
|
39 | - * If $overrideName is set, this node shows up in the tree under a |
|
40 | - * different name. In this case setName() will be disabled. |
|
41 | - * |
|
42 | - * @param string $path |
|
43 | - * @param string $overrideName |
|
44 | - */ |
|
45 | - public function __construct($path, $overrideName = null) |
|
46 | - { |
|
47 | - $this->path = $path; |
|
48 | - $this->overrideName = $overrideName; |
|
49 | - } |
|
36 | + /** |
|
37 | + * Sets up the node, expects a full path name. |
|
38 | + * |
|
39 | + * If $overrideName is set, this node shows up in the tree under a |
|
40 | + * different name. In this case setName() will be disabled. |
|
41 | + * |
|
42 | + * @param string $path |
|
43 | + * @param string $overrideName |
|
44 | + */ |
|
45 | + public function __construct($path, $overrideName = null) |
|
46 | + { |
|
47 | + $this->path = $path; |
|
48 | + $this->overrideName = $overrideName; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the name of the node. |
|
53 | - * |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function getName() |
|
57 | - { |
|
58 | - if ($this->overrideName) { |
|
59 | - return $this->overrideName; |
|
60 | - } |
|
51 | + /** |
|
52 | + * Returns the name of the node. |
|
53 | + * |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function getName() |
|
57 | + { |
|
58 | + if ($this->overrideName) { |
|
59 | + return $this->overrideName; |
|
60 | + } |
|
61 | 61 | |
62 | - list(, $name) = Uri\split($this->path); |
|
62 | + list(, $name) = Uri\split($this->path); |
|
63 | 63 | |
64 | - return $name; |
|
65 | - } |
|
64 | + return $name; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Renames the node. |
|
69 | - * |
|
70 | - * @param string $name The new name |
|
71 | - */ |
|
72 | - public function setName($name) |
|
73 | - { |
|
74 | - if ($this->overrideName) { |
|
75 | - throw new Forbidden('This node cannot be renamed'); |
|
76 | - } |
|
67 | + /** |
|
68 | + * Renames the node. |
|
69 | + * |
|
70 | + * @param string $name The new name |
|
71 | + */ |
|
72 | + public function setName($name) |
|
73 | + { |
|
74 | + if ($this->overrideName) { |
|
75 | + throw new Forbidden('This node cannot be renamed'); |
|
76 | + } |
|
77 | 77 | |
78 | - list($parentPath) = Uri\split($this->path); |
|
79 | - list(, $newName) = Uri\split($name); |
|
78 | + list($parentPath) = Uri\split($this->path); |
|
79 | + list(, $newName) = Uri\split($name); |
|
80 | 80 | |
81 | - $newPath = $parentPath.'/'.$newName; |
|
82 | - rename($this->path, $newPath); |
|
81 | + $newPath = $parentPath.'/'.$newName; |
|
82 | + rename($this->path, $newPath); |
|
83 | 83 | |
84 | - $this->path = $newPath; |
|
85 | - } |
|
84 | + $this->path = $newPath; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Returns the last modification time, as a unix timestamp. |
|
89 | - * |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - public function getLastModified() |
|
93 | - { |
|
94 | - return filemtime($this->path); |
|
95 | - } |
|
87 | + /** |
|
88 | + * Returns the last modification time, as a unix timestamp. |
|
89 | + * |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + public function getLastModified() |
|
93 | + { |
|
94 | + return filemtime($this->path); |
|
95 | + } |
|
96 | 96 | } |
@@ -21,317 +21,317 @@ |
||
21 | 21 | */ |
22 | 22 | class PropPatch |
23 | 23 | { |
24 | - /** |
|
25 | - * Properties that are being updated. |
|
26 | - * |
|
27 | - * This is a key-value list. If the value is null, the property is supposed |
|
28 | - * to be deleted. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $mutations; |
|
24 | + /** |
|
25 | + * Properties that are being updated. |
|
26 | + * |
|
27 | + * This is a key-value list. If the value is null, the property is supposed |
|
28 | + * to be deleted. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $mutations; |
|
33 | 33 | |
34 | - /** |
|
35 | - * A list of properties and the result of the update. The result is in the |
|
36 | - * form of a HTTP status code. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $result = []; |
|
34 | + /** |
|
35 | + * A list of properties and the result of the update. The result is in the |
|
36 | + * form of a HTTP status code. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $result = []; |
|
41 | 41 | |
42 | - /** |
|
43 | - * This is the list of callbacks when we're performing the actual update. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $propertyUpdateCallbacks = []; |
|
42 | + /** |
|
43 | + * This is the list of callbacks when we're performing the actual update. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $propertyUpdateCallbacks = []; |
|
48 | 48 | |
49 | - /** |
|
50 | - * This property will be set to true if the operation failed. |
|
51 | - * |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $failed = false; |
|
49 | + /** |
|
50 | + * This property will be set to true if the operation failed. |
|
51 | + * |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $failed = false; |
|
55 | 55 | |
56 | - /** |
|
57 | - * Constructor. |
|
58 | - * |
|
59 | - * @param array $mutations A list of updates |
|
60 | - */ |
|
61 | - public function __construct(array $mutations) |
|
62 | - { |
|
63 | - $this->mutations = $mutations; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Constructor. |
|
58 | + * |
|
59 | + * @param array $mutations A list of updates |
|
60 | + */ |
|
61 | + public function __construct(array $mutations) |
|
62 | + { |
|
63 | + $this->mutations = $mutations; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Call this function if you wish to handle updating certain properties. |
|
68 | - * For instance, your class may be responsible for handling updates for the |
|
69 | - * {DAV:}displayname property. |
|
70 | - * |
|
71 | - * In that case, call this method with the first argument |
|
72 | - * "{DAV:}displayname" and a second argument that's a method that does the |
|
73 | - * actual updating. |
|
74 | - * |
|
75 | - * It's possible to specify more than one property as an array. |
|
76 | - * |
|
77 | - * The callback must return a boolean or an it. If the result is true, the |
|
78 | - * operation was considered successful. If it's false, it's consided |
|
79 | - * failed. |
|
80 | - * |
|
81 | - * If the result is an integer, we'll use that integer as the http status |
|
82 | - * code associated with the operation. |
|
83 | - * |
|
84 | - * @param string|string[] $properties |
|
85 | - */ |
|
86 | - public function handle($properties, callable $callback) |
|
87 | - { |
|
88 | - $usedProperties = []; |
|
89 | - foreach ((array) $properties as $propertyName) { |
|
90 | - if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) { |
|
91 | - $usedProperties[] = $propertyName; |
|
92 | - // HTTP Accepted |
|
93 | - $this->result[$propertyName] = 202; |
|
94 | - } |
|
95 | - } |
|
66 | + /** |
|
67 | + * Call this function if you wish to handle updating certain properties. |
|
68 | + * For instance, your class may be responsible for handling updates for the |
|
69 | + * {DAV:}displayname property. |
|
70 | + * |
|
71 | + * In that case, call this method with the first argument |
|
72 | + * "{DAV:}displayname" and a second argument that's a method that does the |
|
73 | + * actual updating. |
|
74 | + * |
|
75 | + * It's possible to specify more than one property as an array. |
|
76 | + * |
|
77 | + * The callback must return a boolean or an it. If the result is true, the |
|
78 | + * operation was considered successful. If it's false, it's consided |
|
79 | + * failed. |
|
80 | + * |
|
81 | + * If the result is an integer, we'll use that integer as the http status |
|
82 | + * code associated with the operation. |
|
83 | + * |
|
84 | + * @param string|string[] $properties |
|
85 | + */ |
|
86 | + public function handle($properties, callable $callback) |
|
87 | + { |
|
88 | + $usedProperties = []; |
|
89 | + foreach ((array) $properties as $propertyName) { |
|
90 | + if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) { |
|
91 | + $usedProperties[] = $propertyName; |
|
92 | + // HTTP Accepted |
|
93 | + $this->result[$propertyName] = 202; |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - // Only registering if there's any unhandled properties. |
|
98 | - if (!$usedProperties) { |
|
99 | - return; |
|
100 | - } |
|
101 | - $this->propertyUpdateCallbacks[] = [ |
|
102 | - // If the original argument to this method was a string, we need |
|
103 | - // to also make sure that it stays that way, so the commit function |
|
104 | - // knows how to format the arguments to the callback. |
|
105 | - is_string($properties) ? $properties : $usedProperties, |
|
106 | - $callback, |
|
107 | - ]; |
|
108 | - } |
|
97 | + // Only registering if there's any unhandled properties. |
|
98 | + if (!$usedProperties) { |
|
99 | + return; |
|
100 | + } |
|
101 | + $this->propertyUpdateCallbacks[] = [ |
|
102 | + // If the original argument to this method was a string, we need |
|
103 | + // to also make sure that it stays that way, so the commit function |
|
104 | + // knows how to format the arguments to the callback. |
|
105 | + is_string($properties) ? $properties : $usedProperties, |
|
106 | + $callback, |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Call this function if you wish to handle _all_ properties that haven't |
|
112 | - * been handled by anything else yet. Note that you effectively claim with |
|
113 | - * this that you promise to process _all_ properties that are coming in. |
|
114 | - */ |
|
115 | - public function handleRemaining(callable $callback) |
|
116 | - { |
|
117 | - $properties = $this->getRemainingMutations(); |
|
118 | - if (!$properties) { |
|
119 | - // Nothing to do, don't register callback |
|
120 | - return; |
|
121 | - } |
|
110 | + /** |
|
111 | + * Call this function if you wish to handle _all_ properties that haven't |
|
112 | + * been handled by anything else yet. Note that you effectively claim with |
|
113 | + * this that you promise to process _all_ properties that are coming in. |
|
114 | + */ |
|
115 | + public function handleRemaining(callable $callback) |
|
116 | + { |
|
117 | + $properties = $this->getRemainingMutations(); |
|
118 | + if (!$properties) { |
|
119 | + // Nothing to do, don't register callback |
|
120 | + return; |
|
121 | + } |
|
122 | 122 | |
123 | - foreach ($properties as $propertyName) { |
|
124 | - // HTTP Accepted |
|
125 | - $this->result[$propertyName] = 202; |
|
123 | + foreach ($properties as $propertyName) { |
|
124 | + // HTTP Accepted |
|
125 | + $this->result[$propertyName] = 202; |
|
126 | 126 | |
127 | - $this->propertyUpdateCallbacks[] = [ |
|
128 | - $properties, |
|
129 | - $callback, |
|
130 | - ]; |
|
131 | - } |
|
132 | - } |
|
127 | + $this->propertyUpdateCallbacks[] = [ |
|
128 | + $properties, |
|
129 | + $callback, |
|
130 | + ]; |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Sets the result code for one or more properties. |
|
136 | - * |
|
137 | - * @param string|string[] $properties |
|
138 | - * @param int $resultCode |
|
139 | - */ |
|
140 | - public function setResultCode($properties, $resultCode) |
|
141 | - { |
|
142 | - foreach ((array) $properties as $propertyName) { |
|
143 | - $this->result[$propertyName] = $resultCode; |
|
144 | - } |
|
134 | + /** |
|
135 | + * Sets the result code for one or more properties. |
|
136 | + * |
|
137 | + * @param string|string[] $properties |
|
138 | + * @param int $resultCode |
|
139 | + */ |
|
140 | + public function setResultCode($properties, $resultCode) |
|
141 | + { |
|
142 | + foreach ((array) $properties as $propertyName) { |
|
143 | + $this->result[$propertyName] = $resultCode; |
|
144 | + } |
|
145 | 145 | |
146 | - if ($resultCode >= 400) { |
|
147 | - $this->failed = true; |
|
148 | - } |
|
149 | - } |
|
146 | + if ($resultCode >= 400) { |
|
147 | + $this->failed = true; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Sets the result code for all properties that did not have a result yet. |
|
153 | - * |
|
154 | - * @param int $resultCode |
|
155 | - */ |
|
156 | - public function setRemainingResultCode($resultCode) |
|
157 | - { |
|
158 | - $this->setResultCode( |
|
159 | - $this->getRemainingMutations(), |
|
160 | - $resultCode |
|
161 | - ); |
|
162 | - } |
|
151 | + /** |
|
152 | + * Sets the result code for all properties that did not have a result yet. |
|
153 | + * |
|
154 | + * @param int $resultCode |
|
155 | + */ |
|
156 | + public function setRemainingResultCode($resultCode) |
|
157 | + { |
|
158 | + $this->setResultCode( |
|
159 | + $this->getRemainingMutations(), |
|
160 | + $resultCode |
|
161 | + ); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Returns the list of properties that don't have a result code yet. |
|
166 | - * |
|
167 | - * This method returns a list of property names, but not its values. |
|
168 | - * |
|
169 | - * @return string[] |
|
170 | - */ |
|
171 | - public function getRemainingMutations() |
|
172 | - { |
|
173 | - $remaining = []; |
|
174 | - foreach ($this->mutations as $propertyName => $propValue) { |
|
175 | - if (!isset($this->result[$propertyName])) { |
|
176 | - $remaining[] = $propertyName; |
|
177 | - } |
|
178 | - } |
|
164 | + /** |
|
165 | + * Returns the list of properties that don't have a result code yet. |
|
166 | + * |
|
167 | + * This method returns a list of property names, but not its values. |
|
168 | + * |
|
169 | + * @return string[] |
|
170 | + */ |
|
171 | + public function getRemainingMutations() |
|
172 | + { |
|
173 | + $remaining = []; |
|
174 | + foreach ($this->mutations as $propertyName => $propValue) { |
|
175 | + if (!isset($this->result[$propertyName])) { |
|
176 | + $remaining[] = $propertyName; |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - return $remaining; |
|
181 | - } |
|
180 | + return $remaining; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Returns the list of properties that don't have a result code yet. |
|
185 | - * |
|
186 | - * This method returns list of properties and their values. |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function getRemainingValues() |
|
191 | - { |
|
192 | - $remaining = []; |
|
193 | - foreach ($this->mutations as $propertyName => $propValue) { |
|
194 | - if (!isset($this->result[$propertyName])) { |
|
195 | - $remaining[$propertyName] = $propValue; |
|
196 | - } |
|
197 | - } |
|
183 | + /** |
|
184 | + * Returns the list of properties that don't have a result code yet. |
|
185 | + * |
|
186 | + * This method returns list of properties and their values. |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function getRemainingValues() |
|
191 | + { |
|
192 | + $remaining = []; |
|
193 | + foreach ($this->mutations as $propertyName => $propValue) { |
|
194 | + if (!isset($this->result[$propertyName])) { |
|
195 | + $remaining[$propertyName] = $propValue; |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - return $remaining; |
|
200 | - } |
|
199 | + return $remaining; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Performs the actual update, and calls all callbacks. |
|
204 | - * |
|
205 | - * This method returns true or false depending on if the operation was |
|
206 | - * successful. |
|
207 | - * |
|
208 | - * @return bool |
|
209 | - */ |
|
210 | - public function commit() |
|
211 | - { |
|
212 | - // First we validate if every property has a handler |
|
213 | - foreach ($this->mutations as $propertyName => $value) { |
|
214 | - if (!isset($this->result[$propertyName])) { |
|
215 | - $this->failed = true; |
|
216 | - $this->result[$propertyName] = 403; |
|
217 | - } |
|
218 | - } |
|
202 | + /** |
|
203 | + * Performs the actual update, and calls all callbacks. |
|
204 | + * |
|
205 | + * This method returns true or false depending on if the operation was |
|
206 | + * successful. |
|
207 | + * |
|
208 | + * @return bool |
|
209 | + */ |
|
210 | + public function commit() |
|
211 | + { |
|
212 | + // First we validate if every property has a handler |
|
213 | + foreach ($this->mutations as $propertyName => $value) { |
|
214 | + if (!isset($this->result[$propertyName])) { |
|
215 | + $this->failed = true; |
|
216 | + $this->result[$propertyName] = 403; |
|
217 | + } |
|
218 | + } |
|
219 | 219 | |
220 | - foreach ($this->propertyUpdateCallbacks as $callbackInfo) { |
|
221 | - if ($this->failed) { |
|
222 | - break; |
|
223 | - } |
|
224 | - if (is_string($callbackInfo[0])) { |
|
225 | - $this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]); |
|
226 | - } else { |
|
227 | - $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]); |
|
228 | - } |
|
229 | - } |
|
220 | + foreach ($this->propertyUpdateCallbacks as $callbackInfo) { |
|
221 | + if ($this->failed) { |
|
222 | + break; |
|
223 | + } |
|
224 | + if (is_string($callbackInfo[0])) { |
|
225 | + $this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]); |
|
226 | + } else { |
|
227 | + $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]); |
|
228 | + } |
|
229 | + } |
|
230 | 230 | |
231 | - /* |
|
231 | + /* |
|
232 | 232 | * If anywhere in this operation updating a property failed, we must |
233 | 233 | * update all other properties accordingly. |
234 | 234 | */ |
235 | - if ($this->failed) { |
|
236 | - foreach ($this->result as $propertyName => $status) { |
|
237 | - if (202 === $status) { |
|
238 | - // Failed dependency |
|
239 | - $this->result[$propertyName] = 424; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
235 | + if ($this->failed) { |
|
236 | + foreach ($this->result as $propertyName => $status) { |
|
237 | + if (202 === $status) { |
|
238 | + // Failed dependency |
|
239 | + $this->result[$propertyName] = 424; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | - return !$this->failed; |
|
245 | - } |
|
244 | + return !$this->failed; |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Executes a property callback with the single-property syntax. |
|
249 | - * |
|
250 | - * @param string $propertyName |
|
251 | - */ |
|
252 | - private function doCallBackSingleProp($propertyName, callable $callback) |
|
253 | - { |
|
254 | - $result = $callback($this->mutations[$propertyName]); |
|
255 | - if (is_bool($result)) { |
|
256 | - if ($result) { |
|
257 | - if (is_null($this->mutations[$propertyName])) { |
|
258 | - // Delete |
|
259 | - $result = 204; |
|
260 | - } else { |
|
261 | - // Update |
|
262 | - $result = 200; |
|
263 | - } |
|
264 | - } else { |
|
265 | - // Fail |
|
266 | - $result = 403; |
|
267 | - } |
|
268 | - } |
|
269 | - if (!is_int($result)) { |
|
270 | - throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool'); |
|
271 | - } |
|
272 | - $this->result[$propertyName] = $result; |
|
273 | - if ($result >= 400) { |
|
274 | - $this->failed = true; |
|
275 | - } |
|
276 | - } |
|
247 | + /** |
|
248 | + * Executes a property callback with the single-property syntax. |
|
249 | + * |
|
250 | + * @param string $propertyName |
|
251 | + */ |
|
252 | + private function doCallBackSingleProp($propertyName, callable $callback) |
|
253 | + { |
|
254 | + $result = $callback($this->mutations[$propertyName]); |
|
255 | + if (is_bool($result)) { |
|
256 | + if ($result) { |
|
257 | + if (is_null($this->mutations[$propertyName])) { |
|
258 | + // Delete |
|
259 | + $result = 204; |
|
260 | + } else { |
|
261 | + // Update |
|
262 | + $result = 200; |
|
263 | + } |
|
264 | + } else { |
|
265 | + // Fail |
|
266 | + $result = 403; |
|
267 | + } |
|
268 | + } |
|
269 | + if (!is_int($result)) { |
|
270 | + throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool'); |
|
271 | + } |
|
272 | + $this->result[$propertyName] = $result; |
|
273 | + if ($result >= 400) { |
|
274 | + $this->failed = true; |
|
275 | + } |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Executes a property callback with the multi-property syntax. |
|
280 | - */ |
|
281 | - private function doCallBackMultiProp(array $propertyList, callable $callback) |
|
282 | - { |
|
283 | - $argument = []; |
|
284 | - foreach ($propertyList as $propertyName) { |
|
285 | - $argument[$propertyName] = $this->mutations[$propertyName]; |
|
286 | - } |
|
278 | + /** |
|
279 | + * Executes a property callback with the multi-property syntax. |
|
280 | + */ |
|
281 | + private function doCallBackMultiProp(array $propertyList, callable $callback) |
|
282 | + { |
|
283 | + $argument = []; |
|
284 | + foreach ($propertyList as $propertyName) { |
|
285 | + $argument[$propertyName] = $this->mutations[$propertyName]; |
|
286 | + } |
|
287 | 287 | |
288 | - $result = $callback($argument); |
|
288 | + $result = $callback($argument); |
|
289 | 289 | |
290 | - if (is_array($result)) { |
|
291 | - foreach ($propertyList as $propertyName) { |
|
292 | - if (!isset($result[$propertyName])) { |
|
293 | - $resultCode = 500; |
|
294 | - } else { |
|
295 | - $resultCode = $result[$propertyName]; |
|
296 | - } |
|
297 | - if ($resultCode >= 400) { |
|
298 | - $this->failed = true; |
|
299 | - } |
|
300 | - $this->result[$propertyName] = $resultCode; |
|
301 | - } |
|
302 | - } elseif (true === $result) { |
|
303 | - // Success |
|
304 | - foreach ($argument as $propertyName => $propertyValue) { |
|
305 | - $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200; |
|
306 | - } |
|
307 | - } elseif (false === $result) { |
|
308 | - // Fail :( |
|
309 | - $this->failed = true; |
|
310 | - foreach ($propertyList as $propertyName) { |
|
311 | - $this->result[$propertyName] = 403; |
|
312 | - } |
|
313 | - } else { |
|
314 | - throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool'); |
|
315 | - } |
|
316 | - } |
|
290 | + if (is_array($result)) { |
|
291 | + foreach ($propertyList as $propertyName) { |
|
292 | + if (!isset($result[$propertyName])) { |
|
293 | + $resultCode = 500; |
|
294 | + } else { |
|
295 | + $resultCode = $result[$propertyName]; |
|
296 | + } |
|
297 | + if ($resultCode >= 400) { |
|
298 | + $this->failed = true; |
|
299 | + } |
|
300 | + $this->result[$propertyName] = $resultCode; |
|
301 | + } |
|
302 | + } elseif (true === $result) { |
|
303 | + // Success |
|
304 | + foreach ($argument as $propertyName => $propertyValue) { |
|
305 | + $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200; |
|
306 | + } |
|
307 | + } elseif (false === $result) { |
|
308 | + // Fail :( |
|
309 | + $this->failed = true; |
|
310 | + foreach ($propertyList as $propertyName) { |
|
311 | + $this->result[$propertyName] = 403; |
|
312 | + } |
|
313 | + } else { |
|
314 | + throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool'); |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * Returns the result of the operation. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - public function getResult() |
|
324 | - { |
|
325 | - return $this->result; |
|
326 | - } |
|
318 | + /** |
|
319 | + * Returns the result of the operation. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + public function getResult() |
|
324 | + { |
|
325 | + return $this->result; |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * Returns the full list of mutations. |
|
330 | - * |
|
331 | - * @return array |
|
332 | - */ |
|
333 | - public function getMutations() |
|
334 | - { |
|
335 | - return $this->mutations; |
|
336 | - } |
|
328 | + /** |
|
329 | + * Returns the full list of mutations. |
|
330 | + * |
|
331 | + * @return array |
|
332 | + */ |
|
333 | + public function getMutations() |
|
334 | + { |
|
335 | + return $this->mutations; |
|
336 | + } |
|
337 | 337 | } |
@@ -19,32 +19,32 @@ |
||
19 | 19 | */ |
20 | 20 | class Exception extends \Exception |
21 | 21 | { |
22 | - /** |
|
23 | - * Returns the HTTP statuscode for this exception. |
|
24 | - * |
|
25 | - * @return int |
|
26 | - */ |
|
27 | - public function getHTTPCode() |
|
28 | - { |
|
29 | - return 500; |
|
30 | - } |
|
22 | + /** |
|
23 | + * Returns the HTTP statuscode for this exception. |
|
24 | + * |
|
25 | + * @return int |
|
26 | + */ |
|
27 | + public function getHTTPCode() |
|
28 | + { |
|
29 | + return 500; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * This method allows the exception to include additional information into the WebDAV error response. |
|
34 | - */ |
|
35 | - public function serialize(Server $server, \DOMElement $errorNode) |
|
36 | - { |
|
37 | - } |
|
32 | + /** |
|
33 | + * This method allows the exception to include additional information into the WebDAV error response. |
|
34 | + */ |
|
35 | + public function serialize(Server $server, \DOMElement $errorNode) |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * This method allows the exception to return any extra HTTP response headers. |
|
41 | - * |
|
42 | - * The headers must be returned as an array. |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function getHTTPHeaders(Server $server) |
|
47 | - { |
|
48 | - return []; |
|
49 | - } |
|
39 | + /** |
|
40 | + * This method allows the exception to return any extra HTTP response headers. |
|
41 | + * |
|
42 | + * The headers must be returned as an array. |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function getHTTPHeaders(Server $server) |
|
47 | + { |
|
48 | + return []; |
|
49 | + } |
|
50 | 50 | } |
@@ -24,48 +24,48 @@ |
||
24 | 24 | */ |
25 | 25 | class MkCol extends PropPatch |
26 | 26 | { |
27 | - /** |
|
28 | - * A list of resource-types in clark-notation. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $resourceType; |
|
27 | + /** |
|
28 | + * A list of resource-types in clark-notation. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $resourceType; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Creates the MKCOL object. |
|
36 | - * |
|
37 | - * @param string[] $resourceType list of resourcetype values |
|
38 | - * @param array $mutations list of new properties values |
|
39 | - */ |
|
40 | - public function __construct(array $resourceType, array $mutations) |
|
41 | - { |
|
42 | - $this->resourceType = $resourceType; |
|
43 | - parent::__construct($mutations); |
|
44 | - } |
|
34 | + /** |
|
35 | + * Creates the MKCOL object. |
|
36 | + * |
|
37 | + * @param string[] $resourceType list of resourcetype values |
|
38 | + * @param array $mutations list of new properties values |
|
39 | + */ |
|
40 | + public function __construct(array $resourceType, array $mutations) |
|
41 | + { |
|
42 | + $this->resourceType = $resourceType; |
|
43 | + parent::__construct($mutations); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the resourcetype of the new collection. |
|
48 | - * |
|
49 | - * @return string[] |
|
50 | - */ |
|
51 | - public function getResourceType() |
|
52 | - { |
|
53 | - return $this->resourceType; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Returns the resourcetype of the new collection. |
|
48 | + * |
|
49 | + * @return string[] |
|
50 | + */ |
|
51 | + public function getResourceType() |
|
52 | + { |
|
53 | + return $this->resourceType; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns true or false if the MKCOL operation has at least the specified |
|
58 | - * resource type. |
|
59 | - * |
|
60 | - * If the resourcetype is specified as an array, all resourcetypes are |
|
61 | - * checked. |
|
62 | - * |
|
63 | - * @param string|string[] $resourceType |
|
64 | - * |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function hasResourceType($resourceType) |
|
68 | - { |
|
69 | - return 0 === count(array_diff((array) $resourceType, $this->resourceType)); |
|
70 | - } |
|
56 | + /** |
|
57 | + * Returns true or false if the MKCOL operation has at least the specified |
|
58 | + * resource type. |
|
59 | + * |
|
60 | + * If the resourcetype is specified as an array, all resourcetypes are |
|
61 | + * checked. |
|
62 | + * |
|
63 | + * @param string|string[] $resourceType |
|
64 | + * |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function hasResourceType($resourceType) |
|
68 | + { |
|
69 | + return 0 === count(array_diff((array) $resourceType, $this->resourceType)); |
|
70 | + } |
|
71 | 71 | } |