annotate vendor/sabre/vobject/lib/Property.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 430dbd5346f7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 * Property
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * A property is always in a KEY:VALUE structure, and may optionally contain
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * parameters.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 abstract class Property extends Node {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * Property name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 * This will contain a string such as DTSTART, SUMMARY, FN.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 public $name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 * Property group.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 * This is only used in vcards
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 public $group;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 * List of parameters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 public $parameters = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 * Current value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 * @var mixed
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 protected $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 * In case this is a multi-value property. This string will be used as a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 * delimiter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 * @var string|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 public $delimiter = ';';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 * Creates the generic property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 * Parameters must be specified in key=>value syntax.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * @param Component $root The root document
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 * @param string|array|null $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 * @param array $parameters List of parameters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 * @param string $group The vcard property group
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 public function __construct(Component $root, $name, $value = null, array $parameters = array(), $group = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 $this->name = $name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 $this->group = $group;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 $this->root = $root;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 foreach($parameters as $k=>$v) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 $this->add($k, $v);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 if (!is_null($value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 $this->setValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 * Updates the current value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 * This may be either a single, or multiple strings in an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 * @param string|array $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 public function setValue($value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 $this->value = $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 * Returns the current value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 * This method will always return a singular value. If this was a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 * multi-value object, some decision will be made first on how to represent
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 * it as a string.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 * To get the correct multi-value version, use getParts.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 public function getValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 if (is_array($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 if (count($this->value)==0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 } elseif (count($this->value)===1) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 return $this->value[0];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 return $this->getRawMimeDirValue($this->value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 return $this->value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 * Sets a multi-valued property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 * @param array $parts
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 public function setParts(array $parts) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 $this->value = $parts;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 * Returns a multi-valued property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 * This method always returns an array, if there was only a single value,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 * it will still be wrapped in an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 public function getParts() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 if (is_null($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 } elseif (is_array($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 return $this->value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 return array($this->value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 * Adds a new parameter, and returns the new item.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 * If a parameter with same name already existed, the values will be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 * combined.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 * If nameless parameter is added, we try to guess it's name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 * @param string|null|array $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 * @return Node
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 public function add($name, $value = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 $noName = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 if ($name === null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 $name = Parameter::guessParameterNameByValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 $noName = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 if (isset($this->parameters[strtoupper($name)])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 $this->parameters[strtoupper($name)]->addValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 $param = new Parameter($this->root, $name, $value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 $param->noName = $noName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 $this->parameters[$param->name] = $param;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 * Returns an iterable list of children
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 public function parameters() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 return $this->parameters;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 * Returns the type of value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 * This corresponds to the VALUE= parameter. Every property also has a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 * 'default' valueType.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 abstract public function getValueType();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 * not yet done, but parameters are not included.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 * @param string $val
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 abstract public function setRawMimeDirValue($val);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 * Returns a raw mime-dir representation of the value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 abstract public function getRawMimeDirValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 * Turns the object back into a serialized blob.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 public function serialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 $str = $this->name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 if ($this->group) $str = $this->group . '.' . $this->name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 foreach($this->parameters as $param) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 $str.=';' . $param->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 $str.=':' . $this->getRawMimeDirValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 $out = '';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 while(strlen($str)>0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 if (strlen($str)>75) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 $out.= mb_strcut($str,0,75,'utf-8') . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 $str = ' ' . mb_strcut($str,75,strlen($str),'utf-8');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 $out.=$str . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 $str='';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 return $out;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 * Returns the value, in the format it should be encoded for json.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 * This method must always return an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 public function getJsonValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 return $this->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 * Sets the json value, as it would appear in a jCard or jCal object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 * The value must always be an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 * @param array $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 public function setJsonValue(array $value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 if (count($value)===1) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 $this->setValue(reset($value));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 $this->setValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 * This method returns an array, with the representation as it should be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 * encoded in json. This is used to create jCard or jCal documents.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 public function jsonSerialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 $parameters = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 foreach($this->parameters as $parameter) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 if ($parameter->name === 'VALUE') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 $parameters[strtolower($parameter->name)] = $parameter->jsonSerialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 // In jCard, we need to encode the property-group as a separate 'group'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 // parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 if ($this->group) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 $parameters['group'] = $this->group;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 return array_merge(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 strtolower($this->name),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 (object)$parameters,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 strtolower($this->getValueType()),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 $this->getJsonValue()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 * Called when this object is being cast to a string.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 * If the property only had a single value, you will get just that. In the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 * case the property had multiple values, the contents will be escaped and
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 * combined with ,.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 public function __toString() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 return (string)$this->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 /* ArrayAccess interface {{{ */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 * Checks if an array element exists
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 * @param mixed $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 public function offsetExists($name) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349 if (is_int($name)) return parent::offsetExists($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351 $name = strtoupper($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353 foreach($this->parameters as $parameter) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354 if ($parameter->name == $name) return true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356 return false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 * Returns a parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 * If the parameter does not exist, null is returned.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 * @return Node
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368 public function offsetGet($name) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370 if (is_int($name)) return parent::offsetGet($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371 $name = strtoupper($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373 if (!isset($this->parameters[$name])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
374 return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
375 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
376
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
377 return $this->parameters[$name];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
378
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
379 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
380
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
381 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
382 * Creates a new parameter
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
383 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
384 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
385 * @param mixed $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
386 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
387 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
388 public function offsetSet($name, $value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
389
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
390 if (is_int($name)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
391 parent::offsetSet($name, $value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
392 // @codeCoverageIgnoreStart
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
393 // This will never be reached, because an exception is always
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
394 // thrown.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
395 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
396 // @codeCoverageIgnoreEnd
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
397 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
398
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
399 $param = new Parameter($this->root, $name, $value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
400 $this->parameters[$param->name] = $param;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
401
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
402 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
403
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
404 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
405 * Removes one or more parameters with the specified name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
406 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
407 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
408 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
409 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
410 public function offsetUnset($name) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
411
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
412 if (is_int($name)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
413 parent::offsetUnset($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
414 // @codeCoverageIgnoreStart
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
415 // This will never be reached, because an exception is always
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
416 // thrown.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
417 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
418 // @codeCoverageIgnoreEnd
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
419 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
420
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
421 unset($this->parameters[strtoupper($name)]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
422
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
423 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
424 /* }}} */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
425
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
426 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
427 * This method is automatically called when the object is cloned.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
428 * Specifically, this will ensure all child elements are also cloned.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
429 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
430 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
431 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
432 public function __clone() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
433
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
434 foreach($this->parameters as $key=>$child) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
435 $this->parameters[$key] = clone $child;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
436 $this->parameters[$key]->parent = $this;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
437 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
438
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
439 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
440
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
441 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
442 * Validates the node for correctness.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
443 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
444 * The following options are supported:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
445 * - Node::REPAIR - If something is broken, and automatic repair may
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
446 * be attempted.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
447 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
448 * An array is returned with warnings.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
449 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
450 * Every item in the array has the following properties:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
451 * * level - (number between 1 and 3 with severity information)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
452 * * message - (human readable message)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
453 * * node - (reference to the offending node)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
454 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
455 * @param int $options
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
456 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
457 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
458 public function validate($options = 0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
459
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
460 $warnings = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
461
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
462 // Checking if our value is UTF-8
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
463 if (!StringUtil::isUTF8($this->getRawMimeDirValue())) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
464
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
465 $oldValue = $this->getRawMimeDirValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
466 $level = 3;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
467 if ($options & self::REPAIR) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
468 $newValue = StringUtil::convertToUTF8($oldValue);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
469 if (true || StringUtil::isUTF8($newValue)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
470 $this->setRawMimeDirValue($newValue);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
471 $level = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
472 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
473
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
474 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
475
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
476
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
477 if (preg_match('%([\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', $oldValue, $matches)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
478 $message = 'Property contained a control character (0x' . bin2hex($matches[1]) . ')';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
479 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
480 $message = 'Property is not valid UTF-8! ' . $oldValue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
481 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
482
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
483 $warnings[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
484 'level' => $level,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
485 'message' => $message,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
486 'node' => $this,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
487 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
488 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
489
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
490 // Checking if the propertyname does not contain any invalid bytes.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
491 if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
492 $warnings[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
493 'level' => 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
494 'message' => 'The propertyname: ' . $this->name . ' contains invalid characters. Only A-Z, 0-9 and - are allowed',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
495 'node' => $this,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
496 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
497 if ($options & self::REPAIR) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
498 // Uppercasing and converting underscores to dashes.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
499 $this->name = strtoupper(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
500 str_replace('_', '-', $this->name)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
501 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
502 // Removing every other invalid character
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
503 $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
504
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
505 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
506
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
507 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
508
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
509 // Validating inner parameters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
510 foreach($this->parameters as $param) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
511 $warnings = array_merge($warnings, $param->validate($options));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
512 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
513
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
514 return $warnings;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
515
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
516 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
517
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
518 }