@@ -24,82 +24,82 @@ |
||
24 | 24 | */ |
25 | 25 | class LockDiscovery implements XmlSerializable |
26 | 26 | { |
27 | - /** |
|
28 | - * locks. |
|
29 | - * |
|
30 | - * @var LockInfo[] |
|
31 | - */ |
|
32 | - public $locks; |
|
27 | + /** |
|
28 | + * locks. |
|
29 | + * |
|
30 | + * @var LockInfo[] |
|
31 | + */ |
|
32 | + public $locks; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Hides the {DAV:}lockroot element from the response. |
|
36 | - * |
|
37 | - * It was reported that showing the lockroot in the response can break |
|
38 | - * Office 2000 compatibility. |
|
39 | - * |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - public static $hideLockRoot = false; |
|
34 | + /** |
|
35 | + * Hides the {DAV:}lockroot element from the response. |
|
36 | + * |
|
37 | + * It was reported that showing the lockroot in the response can break |
|
38 | + * Office 2000 compatibility. |
|
39 | + * |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + public static $hideLockRoot = false; |
|
43 | 43 | |
44 | - /** |
|
45 | - * __construct. |
|
46 | - * |
|
47 | - * @param LockInfo[] $locks |
|
48 | - */ |
|
49 | - public function __construct($locks) |
|
50 | - { |
|
51 | - $this->locks = $locks; |
|
52 | - } |
|
44 | + /** |
|
45 | + * __construct. |
|
46 | + * |
|
47 | + * @param LockInfo[] $locks |
|
48 | + */ |
|
49 | + public function __construct($locks) |
|
50 | + { |
|
51 | + $this->locks = $locks; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * The serialize method is called during xml writing. |
|
56 | - * |
|
57 | - * It should use the $writer argument to encode this object into XML. |
|
58 | - * |
|
59 | - * Important note: it is not needed to create the parent element. The |
|
60 | - * parent element is already created, and we only have to worry about |
|
61 | - * attributes, child elements and text (if any). |
|
62 | - * |
|
63 | - * Important note 2: If you are writing any new elements, you are also |
|
64 | - * responsible for closing them. |
|
65 | - */ |
|
66 | - public function xmlSerialize(Writer $writer) |
|
67 | - { |
|
68 | - foreach ($this->locks as $lock) { |
|
69 | - $writer->startElement('{DAV:}activelock'); |
|
54 | + /** |
|
55 | + * The serialize method is called during xml writing. |
|
56 | + * |
|
57 | + * It should use the $writer argument to encode this object into XML. |
|
58 | + * |
|
59 | + * Important note: it is not needed to create the parent element. The |
|
60 | + * parent element is already created, and we only have to worry about |
|
61 | + * attributes, child elements and text (if any). |
|
62 | + * |
|
63 | + * Important note 2: If you are writing any new elements, you are also |
|
64 | + * responsible for closing them. |
|
65 | + */ |
|
66 | + public function xmlSerialize(Writer $writer) |
|
67 | + { |
|
68 | + foreach ($this->locks as $lock) { |
|
69 | + $writer->startElement('{DAV:}activelock'); |
|
70 | 70 | |
71 | - $writer->startElement('{DAV:}lockscope'); |
|
72 | - if (LockInfo::SHARED === $lock->scope) { |
|
73 | - $writer->writeElement('{DAV:}shared'); |
|
74 | - } else { |
|
75 | - $writer->writeElement('{DAV:}exclusive'); |
|
76 | - } |
|
71 | + $writer->startElement('{DAV:}lockscope'); |
|
72 | + if (LockInfo::SHARED === $lock->scope) { |
|
73 | + $writer->writeElement('{DAV:}shared'); |
|
74 | + } else { |
|
75 | + $writer->writeElement('{DAV:}exclusive'); |
|
76 | + } |
|
77 | 77 | |
78 | - $writer->endElement(); // {DAV:}lockscope |
|
78 | + $writer->endElement(); // {DAV:}lockscope |
|
79 | 79 | |
80 | - $writer->startElement('{DAV:}locktype'); |
|
81 | - $writer->writeElement('{DAV:}write'); |
|
82 | - $writer->endElement(); // {DAV:}locktype |
|
80 | + $writer->startElement('{DAV:}locktype'); |
|
81 | + $writer->writeElement('{DAV:}write'); |
|
82 | + $writer->endElement(); // {DAV:}locktype |
|
83 | 83 | |
84 | - if (!self::$hideLockRoot) { |
|
85 | - $writer->startElement('{DAV:}lockroot'); |
|
86 | - $writer->writeElement('{DAV:}href', $writer->contextUri.$lock->uri); |
|
87 | - $writer->endElement(); // {DAV:}lockroot |
|
88 | - } |
|
89 | - $writer->writeElement('{DAV:}depth', (DAV\Server::DEPTH_INFINITY == $lock->depth ? 'infinity' : $lock->depth)); |
|
90 | - $writer->writeElement('{DAV:}timeout', (LockInfo::TIMEOUT_INFINITE === $lock->timeout ? 'Infinite' : 'Second-'.$lock->timeout)); |
|
84 | + if (!self::$hideLockRoot) { |
|
85 | + $writer->startElement('{DAV:}lockroot'); |
|
86 | + $writer->writeElement('{DAV:}href', $writer->contextUri.$lock->uri); |
|
87 | + $writer->endElement(); // {DAV:}lockroot |
|
88 | + } |
|
89 | + $writer->writeElement('{DAV:}depth', (DAV\Server::DEPTH_INFINITY == $lock->depth ? 'infinity' : $lock->depth)); |
|
90 | + $writer->writeElement('{DAV:}timeout', (LockInfo::TIMEOUT_INFINITE === $lock->timeout ? 'Infinite' : 'Second-'.$lock->timeout)); |
|
91 | 91 | |
92 | - // optional according to https://tools.ietf.org/html/rfc4918#section-6.5 |
|
93 | - if (null !== $lock->token && '' !== $lock->token) { |
|
94 | - $writer->startElement('{DAV:}locktoken'); |
|
95 | - $writer->writeElement('{DAV:}href', 'opaquelocktoken:'.$lock->token); |
|
96 | - $writer->endElement(); // {DAV:}locktoken |
|
97 | - } |
|
92 | + // optional according to https://tools.ietf.org/html/rfc4918#section-6.5 |
|
93 | + if (null !== $lock->token && '' !== $lock->token) { |
|
94 | + $writer->startElement('{DAV:}locktoken'); |
|
95 | + $writer->writeElement('{DAV:}href', 'opaquelocktoken:'.$lock->token); |
|
96 | + $writer->endElement(); // {DAV:}locktoken |
|
97 | + } |
|
98 | 98 | |
99 | - if ($lock->owner) { |
|
100 | - $writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner)); |
|
101 | - } |
|
102 | - $writer->endElement(); // {DAV:}activelock |
|
103 | - } |
|
104 | - } |
|
99 | + if ($lock->owner) { |
|
100 | + $writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner)); |
|
101 | + } |
|
102 | + $writer->endElement(); // {DAV:}activelock |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
@@ -24,91 +24,91 @@ |
||
24 | 24 | */ |
25 | 25 | class SupportedMethodSet implements XmlSerializable, HtmlOutput |
26 | 26 | { |
27 | - /** |
|
28 | - * List of methods. |
|
29 | - * |
|
30 | - * @var string[] |
|
31 | - */ |
|
32 | - protected $methods = []; |
|
27 | + /** |
|
28 | + * List of methods. |
|
29 | + * |
|
30 | + * @var string[] |
|
31 | + */ |
|
32 | + protected $methods = []; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Creates the property. |
|
36 | - * |
|
37 | - * @param string[] $methods |
|
38 | - */ |
|
39 | - public function __construct(array $methods) |
|
40 | - { |
|
41 | - $this->methods = $methods; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Creates the property. |
|
36 | + * |
|
37 | + * @param string[] $methods |
|
38 | + */ |
|
39 | + public function __construct(array $methods) |
|
40 | + { |
|
41 | + $this->methods = $methods; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns the list of supported http methods. |
|
46 | - * |
|
47 | - * @return string[] |
|
48 | - */ |
|
49 | - public function getValue() |
|
50 | - { |
|
51 | - return $this->methods; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Returns the list of supported http methods. |
|
46 | + * |
|
47 | + * @return string[] |
|
48 | + */ |
|
49 | + public function getValue() |
|
50 | + { |
|
51 | + return $this->methods; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns true or false if the property contains a specific method. |
|
56 | - * |
|
57 | - * @param string $methodName |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function has($methodName) |
|
62 | - { |
|
63 | - return in_array( |
|
64 | - $methodName, |
|
65 | - $this->methods |
|
66 | - ); |
|
67 | - } |
|
54 | + /** |
|
55 | + * Returns true or false if the property contains a specific method. |
|
56 | + * |
|
57 | + * @param string $methodName |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function has($methodName) |
|
62 | + { |
|
63 | + return in_array( |
|
64 | + $methodName, |
|
65 | + $this->methods |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * The xmlSerialize method is called during xml writing. |
|
71 | - * |
|
72 | - * Use the $writer argument to write its own xml serialization. |
|
73 | - * |
|
74 | - * An important note: do _not_ create a parent element. Any element |
|
75 | - * implementing XmlSerializable should only ever write what's considered |
|
76 | - * its 'inner xml'. |
|
77 | - * |
|
78 | - * The parent of the current element is responsible for writing a |
|
79 | - * containing element. |
|
80 | - * |
|
81 | - * This allows serializers to be re-used for different element names. |
|
82 | - * |
|
83 | - * If you are opening new elements, you must also close them again. |
|
84 | - */ |
|
85 | - public function xmlSerialize(Writer $writer) |
|
86 | - { |
|
87 | - foreach ($this->getValue() as $val) { |
|
88 | - $writer->startElement('{DAV:}supported-method'); |
|
89 | - $writer->writeAttribute('name', $val); |
|
90 | - $writer->endElement(); |
|
91 | - } |
|
92 | - } |
|
69 | + /** |
|
70 | + * The xmlSerialize method is called during xml writing. |
|
71 | + * |
|
72 | + * Use the $writer argument to write its own xml serialization. |
|
73 | + * |
|
74 | + * An important note: do _not_ create a parent element. Any element |
|
75 | + * implementing XmlSerializable should only ever write what's considered |
|
76 | + * its 'inner xml'. |
|
77 | + * |
|
78 | + * The parent of the current element is responsible for writing a |
|
79 | + * containing element. |
|
80 | + * |
|
81 | + * This allows serializers to be re-used for different element names. |
|
82 | + * |
|
83 | + * If you are opening new elements, you must also close them again. |
|
84 | + */ |
|
85 | + public function xmlSerialize(Writer $writer) |
|
86 | + { |
|
87 | + foreach ($this->getValue() as $val) { |
|
88 | + $writer->startElement('{DAV:}supported-method'); |
|
89 | + $writer->writeAttribute('name', $val); |
|
90 | + $writer->endElement(); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Generate html representation for this value. |
|
96 | - * |
|
97 | - * The html output is 100% trusted, and no effort is being made to sanitize |
|
98 | - * it. It's up to the implementor to sanitize user provided values. |
|
99 | - * |
|
100 | - * The output must be in UTF-8. |
|
101 | - * |
|
102 | - * The baseUri parameter is a url to the root of the application, and can |
|
103 | - * be used to construct local links. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function toHtml(HtmlOutputHelper $html) |
|
108 | - { |
|
109 | - return implode( |
|
110 | - ', ', |
|
111 | - array_map([$html, 'h'], $this->getValue()) |
|
112 | - ); |
|
113 | - } |
|
94 | + /** |
|
95 | + * Generate html representation for this value. |
|
96 | + * |
|
97 | + * The html output is 100% trusted, and no effort is being made to sanitize |
|
98 | + * it. It's up to the implementor to sanitize user provided values. |
|
99 | + * |
|
100 | + * The output must be in UTF-8. |
|
101 | + * |
|
102 | + * The baseUri parameter is a url to the root of the application, and can |
|
103 | + * be used to construct local links. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function toHtml(HtmlOutputHelper $html) |
|
108 | + { |
|
109 | + return implode( |
|
110 | + ', ', |
|
111 | + array_map([$html, 'h'], $this->getValue()) |
|
112 | + ); |
|
113 | + } |
|
114 | 114 | } |
@@ -22,99 +22,99 @@ |
||
22 | 22 | */ |
23 | 23 | class ResourceType extends Element\Elements implements HtmlOutput |
24 | 24 | { |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * You can either pass null (for no resourcetype), a string (for a single |
|
29 | - * resourcetype) or an array (for multiple). |
|
30 | - * |
|
31 | - * The resourcetype must be specified in clark-notation |
|
32 | - * |
|
33 | - * @param array|string|null $resourceTypes |
|
34 | - */ |
|
35 | - public function __construct($resourceTypes = null) |
|
36 | - { |
|
37 | - parent::__construct((array) $resourceTypes); |
|
38 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * You can either pass null (for no resourcetype), a string (for a single |
|
29 | + * resourcetype) or an array (for multiple). |
|
30 | + * |
|
31 | + * The resourcetype must be specified in clark-notation |
|
32 | + * |
|
33 | + * @param array|string|null $resourceTypes |
|
34 | + */ |
|
35 | + public function __construct($resourceTypes = null) |
|
36 | + { |
|
37 | + parent::__construct((array) $resourceTypes); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns the values in clark-notation. |
|
42 | - * |
|
43 | - * For example array('{DAV:}collection') |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function getValue() |
|
48 | - { |
|
49 | - return $this->value; |
|
50 | - } |
|
40 | + /** |
|
41 | + * Returns the values in clark-notation. |
|
42 | + * |
|
43 | + * For example array('{DAV:}collection') |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function getValue() |
|
48 | + { |
|
49 | + return $this->value; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Checks if the principal contains a certain value. |
|
54 | - * |
|
55 | - * @param string $type |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function is($type) |
|
60 | - { |
|
61 | - return in_array($type, $this->value); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Checks if the principal contains a certain value. |
|
54 | + * |
|
55 | + * @param string $type |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function is($type) |
|
60 | + { |
|
61 | + return in_array($type, $this->value); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Adds a resourcetype value to this property. |
|
66 | - * |
|
67 | - * @param string $type |
|
68 | - */ |
|
69 | - public function add($type) |
|
70 | - { |
|
71 | - $this->value[] = $type; |
|
72 | - $this->value = array_unique($this->value); |
|
73 | - } |
|
64 | + /** |
|
65 | + * Adds a resourcetype value to this property. |
|
66 | + * |
|
67 | + * @param string $type |
|
68 | + */ |
|
69 | + public function add($type) |
|
70 | + { |
|
71 | + $this->value[] = $type; |
|
72 | + $this->value = array_unique($this->value); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * The deserialize method is called during xml parsing. |
|
77 | - * |
|
78 | - * This method is called statically, this is because in theory this method |
|
79 | - * may be used as a type of constructor, or factory method. |
|
80 | - * |
|
81 | - * Often you want to return an instance of the current class, but you are |
|
82 | - * free to return other data as well. |
|
83 | - * |
|
84 | - * Important note 2: You are responsible for advancing the reader to the |
|
85 | - * next element. Not doing anything will result in a never-ending loop. |
|
86 | - * |
|
87 | - * If you just want to skip parsing for this element altogether, you can |
|
88 | - * just call $reader->next(); |
|
89 | - * |
|
90 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
91 | - * the next element. |
|
92 | - * |
|
93 | - * @return mixed |
|
94 | - */ |
|
95 | - public static function xmlDeserialize(Reader $reader) |
|
96 | - { |
|
97 | - return new self(parent::xmlDeserialize($reader)); |
|
98 | - } |
|
75 | + /** |
|
76 | + * The deserialize method is called during xml parsing. |
|
77 | + * |
|
78 | + * This method is called statically, this is because in theory this method |
|
79 | + * may be used as a type of constructor, or factory method. |
|
80 | + * |
|
81 | + * Often you want to return an instance of the current class, but you are |
|
82 | + * free to return other data as well. |
|
83 | + * |
|
84 | + * Important note 2: You are responsible for advancing the reader to the |
|
85 | + * next element. Not doing anything will result in a never-ending loop. |
|
86 | + * |
|
87 | + * If you just want to skip parsing for this element altogether, you can |
|
88 | + * just call $reader->next(); |
|
89 | + * |
|
90 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
91 | + * the next element. |
|
92 | + * |
|
93 | + * @return mixed |
|
94 | + */ |
|
95 | + public static function xmlDeserialize(Reader $reader) |
|
96 | + { |
|
97 | + return new self(parent::xmlDeserialize($reader)); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Generate html representation for this value. |
|
102 | - * |
|
103 | - * The html output is 100% trusted, and no effort is being made to sanitize |
|
104 | - * it. It's up to the implementor to sanitize user provided values. |
|
105 | - * |
|
106 | - * The output must be in UTF-8. |
|
107 | - * |
|
108 | - * The baseUri parameter is a url to the root of the application, and can |
|
109 | - * be used to construct local links. |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function toHtml(HtmlOutputHelper $html) |
|
114 | - { |
|
115 | - return implode( |
|
116 | - ', ', |
|
117 | - array_map([$html, 'xmlName'], $this->getValue()) |
|
118 | - ); |
|
119 | - } |
|
100 | + /** |
|
101 | + * Generate html representation for this value. |
|
102 | + * |
|
103 | + * The html output is 100% trusted, and no effort is being made to sanitize |
|
104 | + * it. It's up to the implementor to sanitize user provided values. |
|
105 | + * |
|
106 | + * The output must be in UTF-8. |
|
107 | + * |
|
108 | + * The baseUri parameter is a url to the root of the application, and can |
|
109 | + * be used to construct local links. |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function toHtml(HtmlOutputHelper $html) |
|
114 | + { |
|
115 | + return implode( |
|
116 | + ', ', |
|
117 | + array_map([$html, 'xmlName'], $this->getValue()) |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | } |
@@ -23,81 +23,81 @@ |
||
23 | 23 | */ |
24 | 24 | class GetLastModified implements Element |
25 | 25 | { |
26 | - /** |
|
27 | - * time. |
|
28 | - * |
|
29 | - * @var DateTime |
|
30 | - */ |
|
31 | - public $time; |
|
26 | + /** |
|
27 | + * time. |
|
28 | + * |
|
29 | + * @var DateTime |
|
30 | + */ |
|
31 | + public $time; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param int|DateTime $time |
|
37 | - */ |
|
38 | - public function __construct($time) |
|
39 | - { |
|
40 | - if ($time instanceof DateTime) { |
|
41 | - $this->time = clone $time; |
|
42 | - } else { |
|
43 | - $this->time = new DateTime('@'.$time); |
|
44 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param int|DateTime $time |
|
37 | + */ |
|
38 | + public function __construct($time) |
|
39 | + { |
|
40 | + if ($time instanceof DateTime) { |
|
41 | + $this->time = clone $time; |
|
42 | + } else { |
|
43 | + $this->time = new DateTime('@'.$time); |
|
44 | + } |
|
45 | 45 | |
46 | - // Setting timezone to UTC |
|
47 | - $this->time->setTimezone(new DateTimeZone('UTC')); |
|
48 | - } |
|
46 | + // Setting timezone to UTC |
|
47 | + $this->time->setTimezone(new DateTimeZone('UTC')); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * getTime. |
|
52 | - * |
|
53 | - * @return DateTime |
|
54 | - */ |
|
55 | - public function getTime() |
|
56 | - { |
|
57 | - return $this->time; |
|
58 | - } |
|
50 | + /** |
|
51 | + * getTime. |
|
52 | + * |
|
53 | + * @return DateTime |
|
54 | + */ |
|
55 | + public function getTime() |
|
56 | + { |
|
57 | + return $this->time; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The serialize method is called during xml writing. |
|
62 | - * |
|
63 | - * It should use the $writer argument to encode this object into XML. |
|
64 | - * |
|
65 | - * Important note: it is not needed to create the parent element. The |
|
66 | - * parent element is already created, and we only have to worry about |
|
67 | - * attributes, child elements and text (if any). |
|
68 | - * |
|
69 | - * Important note 2: If you are writing any new elements, you are also |
|
70 | - * responsible for closing them. |
|
71 | - */ |
|
72 | - public function xmlSerialize(Writer $writer) |
|
73 | - { |
|
74 | - $writer->write( |
|
75 | - HTTP\toDate($this->time) |
|
76 | - ); |
|
77 | - } |
|
60 | + /** |
|
61 | + * The serialize method is called during xml writing. |
|
62 | + * |
|
63 | + * It should use the $writer argument to encode this object into XML. |
|
64 | + * |
|
65 | + * Important note: it is not needed to create the parent element. The |
|
66 | + * parent element is already created, and we only have to worry about |
|
67 | + * attributes, child elements and text (if any). |
|
68 | + * |
|
69 | + * Important note 2: If you are writing any new elements, you are also |
|
70 | + * responsible for closing them. |
|
71 | + */ |
|
72 | + public function xmlSerialize(Writer $writer) |
|
73 | + { |
|
74 | + $writer->write( |
|
75 | + HTTP\toDate($this->time) |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * The deserialize method is called during xml parsing. |
|
81 | - * |
|
82 | - * This method is called statically, this is because in theory this method |
|
83 | - * may be used as a type of constructor, or factory method. |
|
84 | - * |
|
85 | - * Often you want to return an instance of the current class, but you are |
|
86 | - * free to return other data as well. |
|
87 | - * |
|
88 | - * Important note 2: You are responsible for advancing the reader to the |
|
89 | - * next element. Not doing anything will result in a never-ending loop. |
|
90 | - * |
|
91 | - * If you just want to skip parsing for this element altogether, you can |
|
92 | - * just call $reader->next(); |
|
93 | - * |
|
94 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
95 | - * the next element. |
|
96 | - * |
|
97 | - * @return mixed |
|
98 | - */ |
|
99 | - public static function xmlDeserialize(Reader $reader) |
|
100 | - { |
|
101 | - return new self(new DateTime($reader->parseInnerTree())); |
|
102 | - } |
|
79 | + /** |
|
80 | + * The deserialize method is called during xml parsing. |
|
81 | + * |
|
82 | + * This method is called statically, this is because in theory this method |
|
83 | + * may be used as a type of constructor, or factory method. |
|
84 | + * |
|
85 | + * Often you want to return an instance of the current class, but you are |
|
86 | + * free to return other data as well. |
|
87 | + * |
|
88 | + * Important note 2: You are responsible for advancing the reader to the |
|
89 | + * next element. Not doing anything will result in a never-ending loop. |
|
90 | + * |
|
91 | + * If you just want to skip parsing for this element altogether, you can |
|
92 | + * just call $reader->next(); |
|
93 | + * |
|
94 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
95 | + * the next element. |
|
96 | + * |
|
97 | + * @return mixed |
|
98 | + */ |
|
99 | + public static function xmlDeserialize(Reader $reader) |
|
100 | + { |
|
101 | + return new self(new DateTime($reader->parseInnerTree())); |
|
102 | + } |
|
103 | 103 | } |
@@ -19,69 +19,69 @@ |
||
19 | 19 | */ |
20 | 20 | class Complex extends XmlFragment |
21 | 21 | { |
22 | - /** |
|
23 | - * The deserialize method is called during xml parsing. |
|
24 | - * |
|
25 | - * This method is called statically, this is because in theory this method |
|
26 | - * may be used as a type of constructor, or factory method. |
|
27 | - * |
|
28 | - * Often you want to return an instance of the current class, but you are |
|
29 | - * free to return other data as well. |
|
30 | - * |
|
31 | - * You are responsible for advancing the reader to the next element. Not |
|
32 | - * doing anything will result in a never-ending loop. |
|
33 | - * |
|
34 | - * If you just want to skip parsing for this element altogether, you can |
|
35 | - * just call $reader->next(); |
|
36 | - * |
|
37 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
38 | - * the next element. |
|
39 | - * |
|
40 | - * @return mixed |
|
41 | - */ |
|
42 | - public static function xmlDeserialize(Reader $reader) |
|
43 | - { |
|
44 | - $xml = $reader->readInnerXml(); |
|
22 | + /** |
|
23 | + * The deserialize method is called during xml parsing. |
|
24 | + * |
|
25 | + * This method is called statically, this is because in theory this method |
|
26 | + * may be used as a type of constructor, or factory method. |
|
27 | + * |
|
28 | + * Often you want to return an instance of the current class, but you are |
|
29 | + * free to return other data as well. |
|
30 | + * |
|
31 | + * You are responsible for advancing the reader to the next element. Not |
|
32 | + * doing anything will result in a never-ending loop. |
|
33 | + * |
|
34 | + * If you just want to skip parsing for this element altogether, you can |
|
35 | + * just call $reader->next(); |
|
36 | + * |
|
37 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
38 | + * the next element. |
|
39 | + * |
|
40 | + * @return mixed |
|
41 | + */ |
|
42 | + public static function xmlDeserialize(Reader $reader) |
|
43 | + { |
|
44 | + $xml = $reader->readInnerXml(); |
|
45 | 45 | |
46 | - if (Reader::ELEMENT === $reader->nodeType && $reader->isEmptyElement) { |
|
47 | - // Easy! |
|
48 | - $reader->next(); |
|
46 | + if (Reader::ELEMENT === $reader->nodeType && $reader->isEmptyElement) { |
|
47 | + // Easy! |
|
48 | + $reader->next(); |
|
49 | 49 | |
50 | - return null; |
|
51 | - } |
|
52 | - // Now we have a copy of the inner xml, we need to traverse it to get |
|
53 | - // all the strings. If there's no non-string data, we just return the |
|
54 | - // string, otherwise we return an instance of this class. |
|
55 | - $reader->read(); |
|
50 | + return null; |
|
51 | + } |
|
52 | + // Now we have a copy of the inner xml, we need to traverse it to get |
|
53 | + // all the strings. If there's no non-string data, we just return the |
|
54 | + // string, otherwise we return an instance of this class. |
|
55 | + $reader->read(); |
|
56 | 56 | |
57 | - $nonText = false; |
|
58 | - $text = ''; |
|
57 | + $nonText = false; |
|
58 | + $text = ''; |
|
59 | 59 | |
60 | - while (true) { |
|
61 | - switch ($reader->nodeType) { |
|
62 | - case Reader::ELEMENT: |
|
63 | - $nonText = true; |
|
64 | - $reader->next(); |
|
65 | - continue 2; |
|
66 | - case Reader::TEXT: |
|
67 | - case Reader::CDATA: |
|
68 | - $text .= $reader->value; |
|
69 | - break; |
|
70 | - case Reader::END_ELEMENT: |
|
71 | - break 2; |
|
72 | - } |
|
73 | - $reader->read(); |
|
74 | - } |
|
60 | + while (true) { |
|
61 | + switch ($reader->nodeType) { |
|
62 | + case Reader::ELEMENT: |
|
63 | + $nonText = true; |
|
64 | + $reader->next(); |
|
65 | + continue 2; |
|
66 | + case Reader::TEXT: |
|
67 | + case Reader::CDATA: |
|
68 | + $text .= $reader->value; |
|
69 | + break; |
|
70 | + case Reader::END_ELEMENT: |
|
71 | + break 2; |
|
72 | + } |
|
73 | + $reader->read(); |
|
74 | + } |
|
75 | 75 | |
76 | - // Make sure we advance the cursor one step further. |
|
77 | - $reader->read(); |
|
76 | + // Make sure we advance the cursor one step further. |
|
77 | + $reader->read(); |
|
78 | 78 | |
79 | - if ($nonText) { |
|
80 | - $new = new self($xml); |
|
79 | + if ($nonText) { |
|
80 | + $new = new self($xml); |
|
81 | 81 | |
82 | - return $new; |
|
83 | - } else { |
|
84 | - return $text; |
|
85 | - } |
|
86 | - } |
|
82 | + return $new; |
|
83 | + } else { |
|
84 | + return $text; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
@@ -22,31 +22,31 @@ |
||
22 | 22 | */ |
23 | 23 | class SupportedLock implements XmlSerializable |
24 | 24 | { |
25 | - /** |
|
26 | - * The xmlSerialize method is called during xml writing. |
|
27 | - * |
|
28 | - * Use the $writer argument to write its own xml serialization. |
|
29 | - * |
|
30 | - * An important note: do _not_ create a parent element. Any element |
|
31 | - * implementing XmlSerializable should only ever write what's considered |
|
32 | - * its 'inner xml'. |
|
33 | - * |
|
34 | - * The parent of the current element is responsible for writing a |
|
35 | - * containing element. |
|
36 | - * |
|
37 | - * This allows serializers to be re-used for different element names. |
|
38 | - * |
|
39 | - * If you are opening new elements, you must also close them again. |
|
40 | - */ |
|
41 | - public function xmlSerialize(Writer $writer) |
|
42 | - { |
|
43 | - $writer->writeElement('{DAV:}lockentry', [ |
|
44 | - '{DAV:}lockscope' => ['{DAV:}exclusive' => null], |
|
45 | - '{DAV:}locktype' => ['{DAV:}write' => null], |
|
46 | - ]); |
|
47 | - $writer->writeElement('{DAV:}lockentry', [ |
|
48 | - '{DAV:}lockscope' => ['{DAV:}shared' => null], |
|
49 | - '{DAV:}locktype' => ['{DAV:}write' => null], |
|
50 | - ]); |
|
51 | - } |
|
25 | + /** |
|
26 | + * The xmlSerialize method is called during xml writing. |
|
27 | + * |
|
28 | + * Use the $writer argument to write its own xml serialization. |
|
29 | + * |
|
30 | + * An important note: do _not_ create a parent element. Any element |
|
31 | + * implementing XmlSerializable should only ever write what's considered |
|
32 | + * its 'inner xml'. |
|
33 | + * |
|
34 | + * The parent of the current element is responsible for writing a |
|
35 | + * containing element. |
|
36 | + * |
|
37 | + * This allows serializers to be re-used for different element names. |
|
38 | + * |
|
39 | + * If you are opening new elements, you must also close them again. |
|
40 | + */ |
|
41 | + public function xmlSerialize(Writer $writer) |
|
42 | + { |
|
43 | + $writer->writeElement('{DAV:}lockentry', [ |
|
44 | + '{DAV:}lockscope' => ['{DAV:}exclusive' => null], |
|
45 | + '{DAV:}locktype' => ['{DAV:}write' => null], |
|
46 | + ]); |
|
47 | + $writer->writeElement('{DAV:}lockentry', [ |
|
48 | + '{DAV:}lockscope' => ['{DAV:}shared' => null], |
|
49 | + '{DAV:}locktype' => ['{DAV:}write' => null], |
|
50 | + ]); |
|
51 | + } |
|
52 | 52 | } |
@@ -17,67 +17,67 @@ |
||
17 | 17 | */ |
18 | 18 | interface IFile extends INode |
19 | 19 | { |
20 | - /** |
|
21 | - * Replaces the contents of the file. |
|
22 | - * |
|
23 | - * The data argument is a readable stream resource. |
|
24 | - * |
|
25 | - * After a successful put operation, you may choose to return an ETag. The |
|
26 | - * etag must always be surrounded by double-quotes. These quotes must |
|
27 | - * appear in the actual string you're returning. |
|
28 | - * |
|
29 | - * Clients may use the ETag from a PUT request to later on make sure that |
|
30 | - * when they update the file, the contents haven't changed in the mean |
|
31 | - * time. |
|
32 | - * |
|
33 | - * If you don't plan to store the file byte-by-byte, and you return a |
|
34 | - * different object on a subsequent GET you are strongly recommended to not |
|
35 | - * return an ETag, and just return null. |
|
36 | - * |
|
37 | - * @param resource|string $data |
|
38 | - * |
|
39 | - * @return string|null |
|
40 | - */ |
|
41 | - public function put($data); |
|
20 | + /** |
|
21 | + * Replaces the contents of the file. |
|
22 | + * |
|
23 | + * The data argument is a readable stream resource. |
|
24 | + * |
|
25 | + * After a successful put operation, you may choose to return an ETag. The |
|
26 | + * etag must always be surrounded by double-quotes. These quotes must |
|
27 | + * appear in the actual string you're returning. |
|
28 | + * |
|
29 | + * Clients may use the ETag from a PUT request to later on make sure that |
|
30 | + * when they update the file, the contents haven't changed in the mean |
|
31 | + * time. |
|
32 | + * |
|
33 | + * If you don't plan to store the file byte-by-byte, and you return a |
|
34 | + * different object on a subsequent GET you are strongly recommended to not |
|
35 | + * return an ETag, and just return null. |
|
36 | + * |
|
37 | + * @param resource|string $data |
|
38 | + * |
|
39 | + * @return string|null |
|
40 | + */ |
|
41 | + public function put($data); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns the data. |
|
45 | - * |
|
46 | - * This method may either return a string or a readable stream resource |
|
47 | - * |
|
48 | - * @return mixed |
|
49 | - */ |
|
50 | - public function get(); |
|
43 | + /** |
|
44 | + * Returns the data. |
|
45 | + * |
|
46 | + * This method may either return a string or a readable stream resource |
|
47 | + * |
|
48 | + * @return mixed |
|
49 | + */ |
|
50 | + public function get(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns the mime-type for a file. |
|
54 | - * |
|
55 | - * If null is returned, we'll assume application/octet-stream |
|
56 | - * |
|
57 | - * @return string|null |
|
58 | - */ |
|
59 | - public function getContentType(); |
|
52 | + /** |
|
53 | + * Returns the mime-type for a file. |
|
54 | + * |
|
55 | + * If null is returned, we'll assume application/octet-stream |
|
56 | + * |
|
57 | + * @return string|null |
|
58 | + */ |
|
59 | + public function getContentType(); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the ETag for a file. |
|
63 | - * |
|
64 | - * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
65 | - * |
|
66 | - * Return null if the ETag can not effectively be determined. |
|
67 | - * |
|
68 | - * The ETag must be surrounded by double-quotes, so something like this |
|
69 | - * would make a valid ETag: |
|
70 | - * |
|
71 | - * return '"someetag"'; |
|
72 | - * |
|
73 | - * @return string|null |
|
74 | - */ |
|
75 | - public function getETag(); |
|
61 | + /** |
|
62 | + * Returns the ETag for a file. |
|
63 | + * |
|
64 | + * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
65 | + * |
|
66 | + * Return null if the ETag can not effectively be determined. |
|
67 | + * |
|
68 | + * The ETag must be surrounded by double-quotes, so something like this |
|
69 | + * would make a valid ETag: |
|
70 | + * |
|
71 | + * return '"someetag"'; |
|
72 | + * |
|
73 | + * @return string|null |
|
74 | + */ |
|
75 | + public function getETag(); |
|
76 | 76 | |
77 | - /** |
|
78 | - * Returns the size of the node, in bytes. |
|
79 | - * |
|
80 | - * @return int |
|
81 | - */ |
|
82 | - public function getSize(); |
|
77 | + /** |
|
78 | + * Returns the size of the node, in bytes. |
|
79 | + * |
|
80 | + * @return int |
|
81 | + */ |
|
82 | + public function getSize(); |
|
83 | 83 | } |
@@ -16,197 +16,197 @@ |
||
16 | 16 | */ |
17 | 17 | class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTarget |
18 | 18 | { |
19 | - /** |
|
20 | - * Creates a new file in the directory. |
|
21 | - * |
|
22 | - * Data will either be supplied as a stream resource, or in certain cases |
|
23 | - * as a string. Keep in mind that you may have to support either. |
|
24 | - * |
|
25 | - * After successful creation of the file, you may choose to return the ETag |
|
26 | - * of the new file here. |
|
27 | - * |
|
28 | - * The returned ETag must be surrounded by double-quotes (The quotes should |
|
29 | - * be part of the actual string). |
|
30 | - * |
|
31 | - * If you cannot accurately determine the ETag, you should not return it. |
|
32 | - * If you don't store the file exactly as-is (you're transforming it |
|
33 | - * somehow) you should also not return an ETag. |
|
34 | - * |
|
35 | - * This means that if a subsequent GET to this new file does not exactly |
|
36 | - * return the same contents of what was submitted here, you are strongly |
|
37 | - * recommended to omit the ETag. |
|
38 | - * |
|
39 | - * @param string $name Name of the file |
|
40 | - * @param resource|string $data Initial payload |
|
41 | - * |
|
42 | - * @return string|null |
|
43 | - */ |
|
44 | - public function createFile($name, $data = null) |
|
45 | - { |
|
46 | - // We're not allowing dots |
|
47 | - if ('.' == $name || '..' == $name) { |
|
48 | - throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
49 | - } |
|
50 | - $newPath = $this->path.'/'.$name; |
|
51 | - file_put_contents($newPath, $data); |
|
52 | - clearstatcache(true, $newPath); |
|
53 | - |
|
54 | - return '"'.sha1( |
|
55 | - fileinode($newPath). |
|
56 | - filesize($newPath). |
|
57 | - filemtime($newPath) |
|
58 | - ).'"'; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Creates a new subdirectory. |
|
63 | - * |
|
64 | - * @param string $name |
|
65 | - */ |
|
66 | - public function createDirectory($name) |
|
67 | - { |
|
68 | - // We're not allowing dots |
|
69 | - if ('.' == $name || '..' == $name) { |
|
70 | - throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
71 | - } |
|
72 | - $newPath = $this->path.'/'.$name; |
|
73 | - mkdir($newPath); |
|
74 | - clearstatcache(true, $newPath); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Returns a specific child node, referenced by its name. |
|
79 | - * |
|
80 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
81 | - * exist. |
|
82 | - * |
|
83 | - * @param string $name |
|
84 | - * |
|
85 | - * @throws DAV\Exception\NotFound |
|
86 | - * |
|
87 | - * @return DAV\INode |
|
88 | - */ |
|
89 | - public function getChild($name) |
|
90 | - { |
|
91 | - $path = $this->path.'/'.$name; |
|
92 | - |
|
93 | - if (!file_exists($path)) { |
|
94 | - throw new DAV\Exception\NotFound('File could not be located'); |
|
95 | - } |
|
96 | - if ('.' == $name || '..' == $name) { |
|
97 | - throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
98 | - } |
|
99 | - if (is_dir($path)) { |
|
100 | - return new self($path); |
|
101 | - } else { |
|
102 | - return new File($path); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Checks if a child exists. |
|
108 | - * |
|
109 | - * @param string $name |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function childExists($name) |
|
114 | - { |
|
115 | - if ('.' == $name || '..' == $name) { |
|
116 | - throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
117 | - } |
|
118 | - $path = $this->path.'/'.$name; |
|
119 | - |
|
120 | - return file_exists($path); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns an array with all the child nodes. |
|
125 | - * |
|
126 | - * @return DAV\INode[] |
|
127 | - */ |
|
128 | - public function getChildren() |
|
129 | - { |
|
130 | - $nodes = []; |
|
131 | - $iterator = new \FilesystemIterator( |
|
132 | - $this->path, |
|
133 | - \FilesystemIterator::CURRENT_AS_SELF |
|
134 | - | \FilesystemIterator::SKIP_DOTS |
|
135 | - ); |
|
136 | - |
|
137 | - foreach ($iterator as $entry) { |
|
138 | - $nodes[] = $this->getChild($entry->getFilename()); |
|
139 | - } |
|
140 | - |
|
141 | - return $nodes; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Deletes all files in this directory, and then itself. |
|
146 | - * |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function delete() |
|
150 | - { |
|
151 | - // Deleting all children |
|
152 | - foreach ($this->getChildren() as $child) { |
|
153 | - $child->delete(); |
|
154 | - } |
|
155 | - |
|
156 | - // Removing the directory itself |
|
157 | - rmdir($this->path); |
|
158 | - |
|
159 | - return true; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Returns available diskspace information. |
|
164 | - * |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - public function getQuotaInfo() |
|
168 | - { |
|
169 | - $total = disk_total_space(realpath($this->path)); |
|
170 | - $free = disk_free_space(realpath($this->path)); |
|
171 | - |
|
172 | - return [ |
|
173 | - $total - $free, |
|
174 | - $free, |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Moves a node into this collection. |
|
180 | - * |
|
181 | - * It is up to the implementors to: |
|
182 | - * 1. Create the new resource. |
|
183 | - * 2. Remove the old resource. |
|
184 | - * 3. Transfer any properties or other data. |
|
185 | - * |
|
186 | - * Generally you should make very sure that your collection can easily move |
|
187 | - * the move. |
|
188 | - * |
|
189 | - * If you don't, just return false, which will trigger sabre/dav to handle |
|
190 | - * the move itself. If you return true from this function, the assumption |
|
191 | - * is that the move was successful. |
|
192 | - * |
|
193 | - * @param string $targetName new local file/collection name |
|
194 | - * @param string $sourcePath Full path to source node |
|
195 | - * @param DAV\INode $sourceNode Source node itself |
|
196 | - * |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) |
|
200 | - { |
|
201 | - // We only support FSExt\Directory or FSExt\File objects, so |
|
202 | - // anything else we want to quickly reject. |
|
203 | - if (!$sourceNode instanceof self && !$sourceNode instanceof File) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - // PHP allows us to access protected properties from other objects, as |
|
208 | - // long as they are defined in a class that has a shared inheritance |
|
209 | - // with the current class. |
|
210 | - return rename($sourceNode->path, $this->path.'/'.$targetName); |
|
211 | - } |
|
19 | + /** |
|
20 | + * Creates a new file in the directory. |
|
21 | + * |
|
22 | + * Data will either be supplied as a stream resource, or in certain cases |
|
23 | + * as a string. Keep in mind that you may have to support either. |
|
24 | + * |
|
25 | + * After successful creation of the file, you may choose to return the ETag |
|
26 | + * of the new file here. |
|
27 | + * |
|
28 | + * The returned ETag must be surrounded by double-quotes (The quotes should |
|
29 | + * be part of the actual string). |
|
30 | + * |
|
31 | + * If you cannot accurately determine the ETag, you should not return it. |
|
32 | + * If you don't store the file exactly as-is (you're transforming it |
|
33 | + * somehow) you should also not return an ETag. |
|
34 | + * |
|
35 | + * This means that if a subsequent GET to this new file does not exactly |
|
36 | + * return the same contents of what was submitted here, you are strongly |
|
37 | + * recommended to omit the ETag. |
|
38 | + * |
|
39 | + * @param string $name Name of the file |
|
40 | + * @param resource|string $data Initial payload |
|
41 | + * |
|
42 | + * @return string|null |
|
43 | + */ |
|
44 | + public function createFile($name, $data = null) |
|
45 | + { |
|
46 | + // We're not allowing dots |
|
47 | + if ('.' == $name || '..' == $name) { |
|
48 | + throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
49 | + } |
|
50 | + $newPath = $this->path.'/'.$name; |
|
51 | + file_put_contents($newPath, $data); |
|
52 | + clearstatcache(true, $newPath); |
|
53 | + |
|
54 | + return '"'.sha1( |
|
55 | + fileinode($newPath). |
|
56 | + filesize($newPath). |
|
57 | + filemtime($newPath) |
|
58 | + ).'"'; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Creates a new subdirectory. |
|
63 | + * |
|
64 | + * @param string $name |
|
65 | + */ |
|
66 | + public function createDirectory($name) |
|
67 | + { |
|
68 | + // We're not allowing dots |
|
69 | + if ('.' == $name || '..' == $name) { |
|
70 | + throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
71 | + } |
|
72 | + $newPath = $this->path.'/'.$name; |
|
73 | + mkdir($newPath); |
|
74 | + clearstatcache(true, $newPath); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Returns a specific child node, referenced by its name. |
|
79 | + * |
|
80 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
81 | + * exist. |
|
82 | + * |
|
83 | + * @param string $name |
|
84 | + * |
|
85 | + * @throws DAV\Exception\NotFound |
|
86 | + * |
|
87 | + * @return DAV\INode |
|
88 | + */ |
|
89 | + public function getChild($name) |
|
90 | + { |
|
91 | + $path = $this->path.'/'.$name; |
|
92 | + |
|
93 | + if (!file_exists($path)) { |
|
94 | + throw new DAV\Exception\NotFound('File could not be located'); |
|
95 | + } |
|
96 | + if ('.' == $name || '..' == $name) { |
|
97 | + throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
98 | + } |
|
99 | + if (is_dir($path)) { |
|
100 | + return new self($path); |
|
101 | + } else { |
|
102 | + return new File($path); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Checks if a child exists. |
|
108 | + * |
|
109 | + * @param string $name |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function childExists($name) |
|
114 | + { |
|
115 | + if ('.' == $name || '..' == $name) { |
|
116 | + throw new DAV\Exception\Forbidden('Permission denied to . and ..'); |
|
117 | + } |
|
118 | + $path = $this->path.'/'.$name; |
|
119 | + |
|
120 | + return file_exists($path); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns an array with all the child nodes. |
|
125 | + * |
|
126 | + * @return DAV\INode[] |
|
127 | + */ |
|
128 | + public function getChildren() |
|
129 | + { |
|
130 | + $nodes = []; |
|
131 | + $iterator = new \FilesystemIterator( |
|
132 | + $this->path, |
|
133 | + \FilesystemIterator::CURRENT_AS_SELF |
|
134 | + | \FilesystemIterator::SKIP_DOTS |
|
135 | + ); |
|
136 | + |
|
137 | + foreach ($iterator as $entry) { |
|
138 | + $nodes[] = $this->getChild($entry->getFilename()); |
|
139 | + } |
|
140 | + |
|
141 | + return $nodes; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Deletes all files in this directory, and then itself. |
|
146 | + * |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function delete() |
|
150 | + { |
|
151 | + // Deleting all children |
|
152 | + foreach ($this->getChildren() as $child) { |
|
153 | + $child->delete(); |
|
154 | + } |
|
155 | + |
|
156 | + // Removing the directory itself |
|
157 | + rmdir($this->path); |
|
158 | + |
|
159 | + return true; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Returns available diskspace information. |
|
164 | + * |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + public function getQuotaInfo() |
|
168 | + { |
|
169 | + $total = disk_total_space(realpath($this->path)); |
|
170 | + $free = disk_free_space(realpath($this->path)); |
|
171 | + |
|
172 | + return [ |
|
173 | + $total - $free, |
|
174 | + $free, |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Moves a node into this collection. |
|
180 | + * |
|
181 | + * It is up to the implementors to: |
|
182 | + * 1. Create the new resource. |
|
183 | + * 2. Remove the old resource. |
|
184 | + * 3. Transfer any properties or other data. |
|
185 | + * |
|
186 | + * Generally you should make very sure that your collection can easily move |
|
187 | + * the move. |
|
188 | + * |
|
189 | + * If you don't, just return false, which will trigger sabre/dav to handle |
|
190 | + * the move itself. If you return true from this function, the assumption |
|
191 | + * is that the move was successful. |
|
192 | + * |
|
193 | + * @param string $targetName new local file/collection name |
|
194 | + * @param string $sourcePath Full path to source node |
|
195 | + * @param DAV\INode $sourceNode Source node itself |
|
196 | + * |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) |
|
200 | + { |
|
201 | + // We only support FSExt\Directory or FSExt\File objects, so |
|
202 | + // anything else we want to quickly reject. |
|
203 | + if (!$sourceNode instanceof self && !$sourceNode instanceof File) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + // PHP allows us to access protected properties from other objects, as |
|
208 | + // long as they are defined in a class that has a shared inheritance |
|
209 | + // with the current class. |
|
210 | + return rename($sourceNode->path, $this->path.'/'.$targetName); |
|
211 | + } |
|
212 | 212 | } |
@@ -16,138 +16,138 @@ |
||
16 | 16 | */ |
17 | 17 | class File extends Node implements DAV\PartialUpdate\IPatchSupport |
18 | 18 | { |
19 | - /** |
|
20 | - * Updates the data. |
|
21 | - * |
|
22 | - * Data is a readable stream resource. |
|
23 | - * |
|
24 | - * @param resource|string $data |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function put($data) |
|
29 | - { |
|
30 | - file_put_contents($this->path, $data); |
|
31 | - clearstatcache(true, $this->path); |
|
19 | + /** |
|
20 | + * Updates the data. |
|
21 | + * |
|
22 | + * Data is a readable stream resource. |
|
23 | + * |
|
24 | + * @param resource|string $data |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function put($data) |
|
29 | + { |
|
30 | + file_put_contents($this->path, $data); |
|
31 | + clearstatcache(true, $this->path); |
|
32 | 32 | |
33 | - return $this->getETag(); |
|
34 | - } |
|
33 | + return $this->getETag(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Updates the file based on a range specification. |
|
38 | - * |
|
39 | - * The first argument is the data, which is either a readable stream |
|
40 | - * resource or a string. |
|
41 | - * |
|
42 | - * The second argument is the type of update we're doing. |
|
43 | - * This is either: |
|
44 | - * * 1. append (default) |
|
45 | - * * 2. update based on a start byte |
|
46 | - * * 3. update based on an end byte |
|
47 | - *; |
|
48 | - * The third argument is the start or end byte. |
|
49 | - * |
|
50 | - * After a successful put operation, you may choose to return an ETag. The |
|
51 | - * ETAG must always be surrounded by double-quotes. These quotes must |
|
52 | - * appear in the actual string you're returning. |
|
53 | - * |
|
54 | - * Clients may use the ETag from a PUT request to later on make sure that |
|
55 | - * when they update the file, the contents haven't changed in the mean |
|
56 | - * time. |
|
57 | - * |
|
58 | - * @param resource|string $data |
|
59 | - * @param int $rangeType |
|
60 | - * @param int $offset |
|
61 | - * |
|
62 | - * @return string|null |
|
63 | - */ |
|
64 | - public function patch($data, $rangeType, $offset = null) |
|
65 | - { |
|
66 | - switch ($rangeType) { |
|
67 | - case 1: |
|
68 | - $f = fopen($this->path, 'a'); |
|
69 | - break; |
|
70 | - case 2: |
|
71 | - $f = fopen($this->path, 'c'); |
|
72 | - fseek($f, $offset); |
|
73 | - break; |
|
74 | - case 3: |
|
75 | - $f = fopen($this->path, 'c'); |
|
76 | - fseek($f, $offset, SEEK_END); |
|
77 | - break; |
|
78 | - default: |
|
79 | - $f = fopen($this->path, 'a'); |
|
80 | - break; |
|
81 | - } |
|
82 | - if (is_string($data)) { |
|
83 | - fwrite($f, $data); |
|
84 | - } else { |
|
85 | - stream_copy_to_stream($data, $f); |
|
86 | - } |
|
87 | - fclose($f); |
|
88 | - clearstatcache(true, $this->path); |
|
36 | + /** |
|
37 | + * Updates the file based on a range specification. |
|
38 | + * |
|
39 | + * The first argument is the data, which is either a readable stream |
|
40 | + * resource or a string. |
|
41 | + * |
|
42 | + * The second argument is the type of update we're doing. |
|
43 | + * This is either: |
|
44 | + * * 1. append (default) |
|
45 | + * * 2. update based on a start byte |
|
46 | + * * 3. update based on an end byte |
|
47 | + *; |
|
48 | + * The third argument is the start or end byte. |
|
49 | + * |
|
50 | + * After a successful put operation, you may choose to return an ETag. The |
|
51 | + * ETAG must always be surrounded by double-quotes. These quotes must |
|
52 | + * appear in the actual string you're returning. |
|
53 | + * |
|
54 | + * Clients may use the ETag from a PUT request to later on make sure that |
|
55 | + * when they update the file, the contents haven't changed in the mean |
|
56 | + * time. |
|
57 | + * |
|
58 | + * @param resource|string $data |
|
59 | + * @param int $rangeType |
|
60 | + * @param int $offset |
|
61 | + * |
|
62 | + * @return string|null |
|
63 | + */ |
|
64 | + public function patch($data, $rangeType, $offset = null) |
|
65 | + { |
|
66 | + switch ($rangeType) { |
|
67 | + case 1: |
|
68 | + $f = fopen($this->path, 'a'); |
|
69 | + break; |
|
70 | + case 2: |
|
71 | + $f = fopen($this->path, 'c'); |
|
72 | + fseek($f, $offset); |
|
73 | + break; |
|
74 | + case 3: |
|
75 | + $f = fopen($this->path, 'c'); |
|
76 | + fseek($f, $offset, SEEK_END); |
|
77 | + break; |
|
78 | + default: |
|
79 | + $f = fopen($this->path, 'a'); |
|
80 | + break; |
|
81 | + } |
|
82 | + if (is_string($data)) { |
|
83 | + fwrite($f, $data); |
|
84 | + } else { |
|
85 | + stream_copy_to_stream($data, $f); |
|
86 | + } |
|
87 | + fclose($f); |
|
88 | + clearstatcache(true, $this->path); |
|
89 | 89 | |
90 | - return $this->getETag(); |
|
91 | - } |
|
90 | + return $this->getETag(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Returns the data. |
|
95 | - * |
|
96 | - * @return resource |
|
97 | - */ |
|
98 | - public function get() |
|
99 | - { |
|
100 | - return fopen($this->path, 'r'); |
|
101 | - } |
|
93 | + /** |
|
94 | + * Returns the data. |
|
95 | + * |
|
96 | + * @return resource |
|
97 | + */ |
|
98 | + public function get() |
|
99 | + { |
|
100 | + return fopen($this->path, 'r'); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Delete the current file. |
|
105 | - * |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function delete() |
|
109 | - { |
|
110 | - return unlink($this->path); |
|
111 | - } |
|
103 | + /** |
|
104 | + * Delete the current file. |
|
105 | + * |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function delete() |
|
109 | + { |
|
110 | + return unlink($this->path); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Returns the ETag for a file. |
|
115 | - * |
|
116 | - * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
117 | - * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
118 | - * |
|
119 | - * Return null if the ETag can not effectively be determined |
|
120 | - * |
|
121 | - * @return string|null |
|
122 | - */ |
|
123 | - public function getETag() |
|
124 | - { |
|
125 | - return '"'.sha1( |
|
126 | - fileinode($this->path). |
|
127 | - filesize($this->path). |
|
128 | - filemtime($this->path) |
|
129 | - ).'"'; |
|
130 | - } |
|
113 | + /** |
|
114 | + * Returns the ETag for a file. |
|
115 | + * |
|
116 | + * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. |
|
117 | + * The ETag is an arbitrary string, but MUST be surrounded by double-quotes. |
|
118 | + * |
|
119 | + * Return null if the ETag can not effectively be determined |
|
120 | + * |
|
121 | + * @return string|null |
|
122 | + */ |
|
123 | + public function getETag() |
|
124 | + { |
|
125 | + return '"'.sha1( |
|
126 | + fileinode($this->path). |
|
127 | + filesize($this->path). |
|
128 | + filemtime($this->path) |
|
129 | + ).'"'; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Returns the mime-type for a file. |
|
134 | - * |
|
135 | - * If null is returned, we'll assume application/octet-stream |
|
136 | - * |
|
137 | - * @return string|null |
|
138 | - */ |
|
139 | - public function getContentType() |
|
140 | - { |
|
141 | - return null; |
|
142 | - } |
|
132 | + /** |
|
133 | + * Returns the mime-type for a file. |
|
134 | + * |
|
135 | + * If null is returned, we'll assume application/octet-stream |
|
136 | + * |
|
137 | + * @return string|null |
|
138 | + */ |
|
139 | + public function getContentType() |
|
140 | + { |
|
141 | + return null; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Returns the size of the file, in bytes. |
|
146 | - * |
|
147 | - * @return int |
|
148 | - */ |
|
149 | - public function getSize() |
|
150 | - { |
|
151 | - return filesize($this->path); |
|
152 | - } |
|
144 | + /** |
|
145 | + * Returns the size of the file, in bytes. |
|
146 | + * |
|
147 | + * @return int |
|
148 | + */ |
|
149 | + public function getSize() |
|
150 | + { |
|
151 | + return filesize($this->path); |
|
152 | + } |
|
153 | 153 | } |