1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
/**
* {DAV:}resourcetype property
*
* This class represents the {DAV:}resourcetype property, as defined in:
*
* https://tools.ietf.org/html/rfc4918#section-15.9
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ResourceType extends Element\Elements implements HtmlOutput {
/**
* Constructor
*
* You can either pass null (for no resourcetype), a string (for a single
* resourcetype) or an array (for multiple).
*
* The resourcetype must be specified in clark-notation
*
* @param array|string|null $resourceTypes
*/
function __construct($resourceTypes = null) {
parent::__construct((array)$resourceTypes);
}
/**
* Returns the values in clark-notation
*
* For example array('{DAV:}collection')
*
* @return array
*/
function getValue() {
return $this->value;
}
/**
* Checks if the principal contains a certain value
*
* @param string $type
* @return bool
*/
function is($type) {
return in_array($type, $this->value);
}
/**
* Adds a resourcetype value to this property
*
* @param string $type
* @return void
*/
function add($type) {
$this->value[] = $type;
$this->value = array_unique($this->value);
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* Important note 2: You are responsible for advancing the reader to the
* next element. Not doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @param Reader $reader
* @return mixed
*/
static function xmlDeserialize(Reader $reader) {
return
new self(parent::xmlDeserialize($reader));
}
/**
* Generate html representation for this value.
*
* The html output is 100% trusted, and no effort is being made to sanitize
* it. It's up to the implementor to sanitize user provided values.
*
* The output must be in UTF-8.
*
* The baseUri parameter is a url to the root of the application, and can
* be used to construct local links.
*
* @param HtmlOutputHelper $html
* @return string
*/
function toHtml(HtmlOutputHelper $html) {
return implode(
', ',
array_map([$html, 'xmlName'], $this->getValue())
);
}
}
|