annotate vendor/sabre/vobject/lib/Parameter.php @ 8:899c8c6a0519

distro
author Charlie Root
date Sat, 13 Jan 2018 09:21:07 -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 use
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 ArrayObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * VObject Parameter
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * This class represents a parameter. A parameter is always tied to a property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * In the case of:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * DTSTART;VALUE=DATE:20101108
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * VALUE=DATE would be the parameter name and value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 class Parameter extends Node {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * Parameter name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 public $name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 * vCard 2.1 allows parameters to be encoded without a name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 * We can deduce the parameter name based on it's value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 * @var bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 public $noName = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 * Parameter value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 protected $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 * Sets up the object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 * It's recommended to use the create:: factory method instead.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 * @param string $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 public function __construct(Document $root, $name, $value = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 $this->name = strtoupper($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 $this->root = $root;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 if (is_null($name)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 $this->noName = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 $this->name = static::guessParameterNameByValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 // If guessParameterNameByValue() returns an empty string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 // above, we're actually dealing with a parameter that has no value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 // In that case we have to move the value to the name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 if ($this->name === '') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 $this->noName = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 $this->name = strtoupper($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 $this->setValue($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 * Try to guess property name by value, can be used for vCard 2.1 nameless parameters.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 * Figuring out what the name should have been. Note that a ton of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 * these are rather silly in 2014 and would probably rarely be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 * used, but we like to be complete.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 * @param string $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 public static function guessParameterNameByValue($value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 switch(strtoupper($value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 // Encodings
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 case '7-BIT' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 case 'QUOTED-PRINTABLE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 case 'BASE64' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 $name = 'ENCODING';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 // Common types
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 case 'WORK' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 case 'HOME' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 case 'PREF' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 // Delivery Label Type
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 case 'DOM' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 case 'INTL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 case 'POSTAL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 case 'PARCEL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 // Telephone types
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 case 'VOICE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 case 'FAX' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 case 'MSG' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 case 'CELL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 case 'PAGER' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 case 'BBS' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 case 'MODEM' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 case 'CAR' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 case 'ISDN' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 case 'VIDEO' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 // EMAIL types (lol)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 case 'AOL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 case 'APPLELINK' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 case 'ATTMAIL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 case 'CIS' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 case 'EWORLD' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 case 'INTERNET' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 case 'IBMMAIL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 case 'MCIMAIL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 case 'POWERSHARE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 case 'PRODIGY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 case 'TLX' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 case 'X400' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 // Photo / Logo format types
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 case 'GIF' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 case 'CGM' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134 case 'WMF' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 case 'BMP' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 case 'DIB' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 case 'PICT' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138 case 'TIFF' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 case 'PDF ':
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 case 'PS' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 case 'JPEG' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 case 'MPEG' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 case 'MPEG2' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 case 'AVI' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 case 'QTIME' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 // Sound Digital Audio Type
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 case 'WAVE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 case 'PCM' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 case 'AIFF' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 // Key types
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 case 'X509' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 case 'PGP' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 $name = 'TYPE';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 // Value types
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 case 'INLINE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 case 'URL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 case 'CONTENT-ID' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 case 'CID' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 $name = 'VALUE';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 default:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 $name = '';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 return $name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 * Updates the current value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 * This may be either a single, or multiple strings in an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 * @param string|array $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 public function setValue($value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 $this->value = $value;
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 the current value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 * This method will always return a string, or null. If there were multiple
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 * values, it will automatically concatinate them (separated by comma).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 * @return string|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 public function getValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 if (is_array($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 return implode(',' , $this->value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 return $this->value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 * Sets multiple values for this parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 * @param array $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 public function setParts(array $value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 $this->value = $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 * Returns all values for this parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 * If there were no values, an empty array will be returned.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 public function getParts() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 if (is_array($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 return $this->value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 } elseif (is_null($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 return array($this->value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 * Adds a value to this parameter
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 * If the argument is specified as an array, all items will be added to the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 * parameter value list.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 * @param string|array $part
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 public function addValue($part) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 if (is_null($this->value)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 $this->value = $part;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 $this->value = array_merge((array)$this->value, (array)$part);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252
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 * Checks if this parameter contains the specified value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 * This is a case-insensitive match. It makes sense to call this for for
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 * instance the TYPE parameter, to see if it contains a keyword such as
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 * 'WORK' or 'FAX'.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 * @param string $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 public function has($value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 return in_array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 strtolower($value),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 array_map('strtolower', (array)$this->value)
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 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 * Turns the object back into a serialized blob.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 public function serialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 $value = $this->getParts();
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)===0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 return $this->name . '=';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 if ($this->root->getDocumentType() === Document::VCARD21 && $this->noName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 return implode(';', $value);
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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 return $this->name . '=' . array_reduce(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 $value,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 function($out, $item) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 if (!is_null($out)) $out.=',';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 // If there's no special characters in the string, we'll use the simple
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300 // format.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 // The list of special characters is defined as:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 // Any character except CONTROL, DQUOTE, ";", ":", ","
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 // by the iCalendar spec:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 // https://tools.ietf.org/html/rfc5545#section-3.1
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 // And we add ^ to that because of:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 // https://tools.ietf.org/html/rfc6868
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312 // But we've found that iCal (7.0, shipped with OSX 10.9)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 // severaly trips on + characters not being quoted, so we
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 // added + as well.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 if (!preg_match('#(?: [\n":;\^,\+] )#x', $item)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 return $out.$item;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 // Enclosing in double-quotes, and using RFC6868 for encoding any
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 // special characters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 $out.='"' . strtr(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 $item,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 '^' => '^^',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 "\n" => '^n',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 '"' => '^\'',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 )
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 ) . '"';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 return $out;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337 * This method returns an array, with the representation as it should be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 * encoded in json. This is used to create jCard or jCal documents.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 public function jsonSerialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 return $this->value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349 * Called when this object is being cast to a string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353 public function __toString() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 return (string)$this->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356
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 * Returns the iterator for this object
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362 * @return ElementList
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 public function getIterator() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 if (!is_null($this->iterator))
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367 return $this->iterator;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369 return $this->iterator = new ArrayObject((array)$this->value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373 }