@@ -15,49 +15,49 @@ |
||
15 | 15 | */ |
16 | 16 | class CalAddress extends Text |
17 | 17 | { |
18 | - /** |
|
19 | - * In case this is a multi-value property. This string will be used as a |
|
20 | - * delimiter. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $delimiter = ''; |
|
18 | + /** |
|
19 | + * In case this is a multi-value property. This string will be used as a |
|
20 | + * delimiter. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $delimiter = ''; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the type of value. |
|
28 | - * |
|
29 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
30 | - * 'default' valueType. |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getValueType() |
|
35 | - { |
|
36 | - return 'CAL-ADDRESS'; |
|
37 | - } |
|
26 | + /** |
|
27 | + * Returns the type of value. |
|
28 | + * |
|
29 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
30 | + * 'default' valueType. |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getValueType() |
|
35 | + { |
|
36 | + return 'CAL-ADDRESS'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * This returns a normalized form of the value. |
|
41 | - * |
|
42 | - * This is primarily used right now to turn mixed-cased schemes in user |
|
43 | - * uris to lower-case. |
|
44 | - * |
|
45 | - * Evolution in particular tends to encode mailto: as MAILTO:. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getNormalizedValue() |
|
50 | - { |
|
51 | - $input = $this->getValue(); |
|
52 | - if (!strpos($input, ':')) { |
|
53 | - return $input; |
|
54 | - } |
|
55 | - list($schema, $everythingElse) = explode(':', $input, 2); |
|
56 | - $schema = strtolower($schema); |
|
57 | - if ('mailto' === $schema) { |
|
58 | - $everythingElse = strtolower($everythingElse); |
|
59 | - } |
|
39 | + /** |
|
40 | + * This returns a normalized form of the value. |
|
41 | + * |
|
42 | + * This is primarily used right now to turn mixed-cased schemes in user |
|
43 | + * uris to lower-case. |
|
44 | + * |
|
45 | + * Evolution in particular tends to encode mailto: as MAILTO:. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getNormalizedValue() |
|
50 | + { |
|
51 | + $input = $this->getValue(); |
|
52 | + if (!strpos($input, ':')) { |
|
53 | + return $input; |
|
54 | + } |
|
55 | + list($schema, $everythingElse) = explode(':', $input, 2); |
|
56 | + $schema = strtolower($schema); |
|
57 | + if ('mailto' === $schema) { |
|
58 | + $everythingElse = strtolower($everythingElse); |
|
59 | + } |
|
60 | 60 | |
61 | - return $schema.':'.$everythingElse; |
|
62 | - } |
|
61 | + return $schema.':'.$everythingElse; |
|
62 | + } |
|
63 | 63 | } |
@@ -26,339 +26,339 @@ |
||
26 | 26 | */ |
27 | 27 | class DateTime extends Property |
28 | 28 | { |
29 | - /** |
|
30 | - * In case this is a multi-value property. This string will be used as a |
|
31 | - * delimiter. |
|
32 | - * |
|
33 | - * @var string|null |
|
34 | - */ |
|
35 | - public $delimiter = ','; |
|
29 | + /** |
|
30 | + * In case this is a multi-value property. This string will be used as a |
|
31 | + * delimiter. |
|
32 | + * |
|
33 | + * @var string|null |
|
34 | + */ |
|
35 | + public $delimiter = ','; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Sets a multi-valued property. |
|
39 | - * |
|
40 | - * You may also specify DateTime objects here. |
|
41 | - */ |
|
42 | - public function setParts(array $parts) |
|
43 | - { |
|
44 | - if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { |
|
45 | - $this->setDateTimes($parts); |
|
46 | - } else { |
|
47 | - parent::setParts($parts); |
|
48 | - } |
|
49 | - } |
|
37 | + /** |
|
38 | + * Sets a multi-valued property. |
|
39 | + * |
|
40 | + * You may also specify DateTime objects here. |
|
41 | + */ |
|
42 | + public function setParts(array $parts) |
|
43 | + { |
|
44 | + if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { |
|
45 | + $this->setDateTimes($parts); |
|
46 | + } else { |
|
47 | + parent::setParts($parts); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Updates the current value. |
|
53 | - * |
|
54 | - * This may be either a single, or multiple strings in an array. |
|
55 | - * |
|
56 | - * Instead of strings, you may also use DateTime here. |
|
57 | - * |
|
58 | - * @param string|array|DateTimeInterface $value |
|
59 | - */ |
|
60 | - public function setValue($value) |
|
61 | - { |
|
62 | - if (is_array($value) && isset($value[0]) && $value[0] instanceof DateTimeInterface) { |
|
63 | - $this->setDateTimes($value); |
|
64 | - } elseif ($value instanceof DateTimeInterface) { |
|
65 | - $this->setDateTimes([$value]); |
|
66 | - } else { |
|
67 | - parent::setValue($value); |
|
68 | - } |
|
69 | - } |
|
51 | + /** |
|
52 | + * Updates the current value. |
|
53 | + * |
|
54 | + * This may be either a single, or multiple strings in an array. |
|
55 | + * |
|
56 | + * Instead of strings, you may also use DateTime here. |
|
57 | + * |
|
58 | + * @param string|array|DateTimeInterface $value |
|
59 | + */ |
|
60 | + public function setValue($value) |
|
61 | + { |
|
62 | + if (is_array($value) && isset($value[0]) && $value[0] instanceof DateTimeInterface) { |
|
63 | + $this->setDateTimes($value); |
|
64 | + } elseif ($value instanceof DateTimeInterface) { |
|
65 | + $this->setDateTimes([$value]); |
|
66 | + } else { |
|
67 | + parent::setValue($value); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
73 | - * |
|
74 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
75 | - * not yet done, but parameters are not included. |
|
76 | - * |
|
77 | - * @param string $val |
|
78 | - */ |
|
79 | - public function setRawMimeDirValue($val) |
|
80 | - { |
|
81 | - $this->setValue(explode($this->delimiter, $val)); |
|
82 | - } |
|
71 | + /** |
|
72 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
73 | + * |
|
74 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
75 | + * not yet done, but parameters are not included. |
|
76 | + * |
|
77 | + * @param string $val |
|
78 | + */ |
|
79 | + public function setRawMimeDirValue($val) |
|
80 | + { |
|
81 | + $this->setValue(explode($this->delimiter, $val)); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Returns a raw mime-dir representation of the value. |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getRawMimeDirValue() |
|
90 | - { |
|
91 | - return implode($this->delimiter, $this->getParts()); |
|
92 | - } |
|
84 | + /** |
|
85 | + * Returns a raw mime-dir representation of the value. |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getRawMimeDirValue() |
|
90 | + { |
|
91 | + return implode($this->delimiter, $this->getParts()); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Returns true if this is a DATE-TIME value, false if it's a DATE. |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function hasTime() |
|
100 | - { |
|
101 | - return 'DATE' !== strtoupper((string) $this['VALUE']); |
|
102 | - } |
|
94 | + /** |
|
95 | + * Returns true if this is a DATE-TIME value, false if it's a DATE. |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function hasTime() |
|
100 | + { |
|
101 | + return 'DATE' !== strtoupper((string) $this['VALUE']); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Returns true if this is a floating DATE or DATE-TIME. |
|
106 | - * |
|
107 | - * Note that DATE is always floating. |
|
108 | - */ |
|
109 | - public function isFloating() |
|
110 | - { |
|
111 | - return |
|
112 | - !$this->hasTime() || |
|
113 | - ( |
|
114 | - !isset($this['TZID']) && |
|
115 | - false === strpos($this->getValue(), 'Z') |
|
116 | - ); |
|
117 | - } |
|
104 | + /** |
|
105 | + * Returns true if this is a floating DATE or DATE-TIME. |
|
106 | + * |
|
107 | + * Note that DATE is always floating. |
|
108 | + */ |
|
109 | + public function isFloating() |
|
110 | + { |
|
111 | + return |
|
112 | + !$this->hasTime() || |
|
113 | + ( |
|
114 | + !isset($this['TZID']) && |
|
115 | + false === strpos($this->getValue(), 'Z') |
|
116 | + ); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Returns a date-time value. |
|
121 | - * |
|
122 | - * Note that if this property contained more than 1 date-time, only the |
|
123 | - * first will be returned. To get an array with multiple values, call |
|
124 | - * getDateTimes. |
|
125 | - * |
|
126 | - * If no timezone information is known, because it's either an all-day |
|
127 | - * property or floating time, we will use the DateTimeZone argument to |
|
128 | - * figure out the exact date. |
|
129 | - * |
|
130 | - * @param DateTimeZone $timeZone |
|
131 | - * |
|
132 | - * @return \DateTimeImmutable |
|
133 | - */ |
|
134 | - public function getDateTime(DateTimeZone $timeZone = null) |
|
135 | - { |
|
136 | - $dt = $this->getDateTimes($timeZone); |
|
137 | - if (!$dt) { |
|
138 | - return; |
|
139 | - } |
|
119 | + /** |
|
120 | + * Returns a date-time value. |
|
121 | + * |
|
122 | + * Note that if this property contained more than 1 date-time, only the |
|
123 | + * first will be returned. To get an array with multiple values, call |
|
124 | + * getDateTimes. |
|
125 | + * |
|
126 | + * If no timezone information is known, because it's either an all-day |
|
127 | + * property or floating time, we will use the DateTimeZone argument to |
|
128 | + * figure out the exact date. |
|
129 | + * |
|
130 | + * @param DateTimeZone $timeZone |
|
131 | + * |
|
132 | + * @return \DateTimeImmutable |
|
133 | + */ |
|
134 | + public function getDateTime(DateTimeZone $timeZone = null) |
|
135 | + { |
|
136 | + $dt = $this->getDateTimes($timeZone); |
|
137 | + if (!$dt) { |
|
138 | + return; |
|
139 | + } |
|
140 | 140 | |
141 | - return $dt[0]; |
|
142 | - } |
|
141 | + return $dt[0]; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Returns multiple date-time values. |
|
146 | - * |
|
147 | - * If no timezone information is known, because it's either an all-day |
|
148 | - * property or floating time, we will use the DateTimeZone argument to |
|
149 | - * figure out the exact date. |
|
150 | - * |
|
151 | - * @param DateTimeZone $timeZone |
|
152 | - * |
|
153 | - * @return \DateTimeImmutable[] |
|
154 | - * @return \DateTime[] |
|
155 | - */ |
|
156 | - public function getDateTimes(DateTimeZone $timeZone = null) |
|
157 | - { |
|
158 | - // Does the property have a TZID? |
|
159 | - $tzid = $this['TZID']; |
|
144 | + /** |
|
145 | + * Returns multiple date-time values. |
|
146 | + * |
|
147 | + * If no timezone information is known, because it's either an all-day |
|
148 | + * property or floating time, we will use the DateTimeZone argument to |
|
149 | + * figure out the exact date. |
|
150 | + * |
|
151 | + * @param DateTimeZone $timeZone |
|
152 | + * |
|
153 | + * @return \DateTimeImmutable[] |
|
154 | + * @return \DateTime[] |
|
155 | + */ |
|
156 | + public function getDateTimes(DateTimeZone $timeZone = null) |
|
157 | + { |
|
158 | + // Does the property have a TZID? |
|
159 | + $tzid = $this['TZID']; |
|
160 | 160 | |
161 | - if ($tzid) { |
|
162 | - $timeZone = TimeZoneUtil::getTimeZone((string) $tzid, $this->root); |
|
163 | - } |
|
161 | + if ($tzid) { |
|
162 | + $timeZone = TimeZoneUtil::getTimeZone((string) $tzid, $this->root); |
|
163 | + } |
|
164 | 164 | |
165 | - $dts = []; |
|
166 | - foreach ($this->getParts() as $part) { |
|
167 | - $dts[] = DateTimeParser::parse($part, $timeZone); |
|
168 | - } |
|
165 | + $dts = []; |
|
166 | + foreach ($this->getParts() as $part) { |
|
167 | + $dts[] = DateTimeParser::parse($part, $timeZone); |
|
168 | + } |
|
169 | 169 | |
170 | - return $dts; |
|
171 | - } |
|
170 | + return $dts; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Sets the property as a DateTime object. |
|
175 | - * |
|
176 | - * @param bool isFloating If set to true, timezones will be ignored |
|
177 | - */ |
|
178 | - public function setDateTime(DateTimeInterface $dt, $isFloating = false) |
|
179 | - { |
|
180 | - $this->setDateTimes([$dt], $isFloating); |
|
181 | - } |
|
173 | + /** |
|
174 | + * Sets the property as a DateTime object. |
|
175 | + * |
|
176 | + * @param bool isFloating If set to true, timezones will be ignored |
|
177 | + */ |
|
178 | + public function setDateTime(DateTimeInterface $dt, $isFloating = false) |
|
179 | + { |
|
180 | + $this->setDateTimes([$dt], $isFloating); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Sets the property as multiple date-time objects. |
|
185 | - * |
|
186 | - * The first value will be used as a reference for the timezones, and all |
|
187 | - * the other values will be adjusted for that timezone |
|
188 | - * |
|
189 | - * @param DateTimeInterface[] $dt |
|
190 | - * @param bool isFloating If set to true, timezones will be ignored |
|
191 | - */ |
|
192 | - public function setDateTimes(array $dt, $isFloating = false) |
|
193 | - { |
|
194 | - $values = []; |
|
183 | + /** |
|
184 | + * Sets the property as multiple date-time objects. |
|
185 | + * |
|
186 | + * The first value will be used as a reference for the timezones, and all |
|
187 | + * the other values will be adjusted for that timezone |
|
188 | + * |
|
189 | + * @param DateTimeInterface[] $dt |
|
190 | + * @param bool isFloating If set to true, timezones will be ignored |
|
191 | + */ |
|
192 | + public function setDateTimes(array $dt, $isFloating = false) |
|
193 | + { |
|
194 | + $values = []; |
|
195 | 195 | |
196 | - if ($this->hasTime()) { |
|
197 | - $tz = null; |
|
198 | - $isUtc = false; |
|
196 | + if ($this->hasTime()) { |
|
197 | + $tz = null; |
|
198 | + $isUtc = false; |
|
199 | 199 | |
200 | - foreach ($dt as $d) { |
|
201 | - if ($isFloating) { |
|
202 | - $values[] = $d->format('Ymd\\THis'); |
|
203 | - continue; |
|
204 | - } |
|
205 | - if (is_null($tz)) { |
|
206 | - $tz = $d->getTimeZone(); |
|
207 | - $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z', '+00:00']); |
|
208 | - if (!$isUtc) { |
|
209 | - $this->offsetSet('TZID', $tz->getName()); |
|
210 | - } |
|
211 | - } else { |
|
212 | - $d = $d->setTimeZone($tz); |
|
213 | - } |
|
200 | + foreach ($dt as $d) { |
|
201 | + if ($isFloating) { |
|
202 | + $values[] = $d->format('Ymd\\THis'); |
|
203 | + continue; |
|
204 | + } |
|
205 | + if (is_null($tz)) { |
|
206 | + $tz = $d->getTimeZone(); |
|
207 | + $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z', '+00:00']); |
|
208 | + if (!$isUtc) { |
|
209 | + $this->offsetSet('TZID', $tz->getName()); |
|
210 | + } |
|
211 | + } else { |
|
212 | + $d = $d->setTimeZone($tz); |
|
213 | + } |
|
214 | 214 | |
215 | - if ($isUtc) { |
|
216 | - $values[] = $d->format('Ymd\\THis\\Z'); |
|
217 | - } else { |
|
218 | - $values[] = $d->format('Ymd\\THis'); |
|
219 | - } |
|
220 | - } |
|
221 | - if ($isUtc || $isFloating) { |
|
222 | - $this->offsetUnset('TZID'); |
|
223 | - } |
|
224 | - } else { |
|
225 | - foreach ($dt as $d) { |
|
226 | - $values[] = $d->format('Ymd'); |
|
227 | - } |
|
228 | - $this->offsetUnset('TZID'); |
|
229 | - } |
|
215 | + if ($isUtc) { |
|
216 | + $values[] = $d->format('Ymd\\THis\\Z'); |
|
217 | + } else { |
|
218 | + $values[] = $d->format('Ymd\\THis'); |
|
219 | + } |
|
220 | + } |
|
221 | + if ($isUtc || $isFloating) { |
|
222 | + $this->offsetUnset('TZID'); |
|
223 | + } |
|
224 | + } else { |
|
225 | + foreach ($dt as $d) { |
|
226 | + $values[] = $d->format('Ymd'); |
|
227 | + } |
|
228 | + $this->offsetUnset('TZID'); |
|
229 | + } |
|
230 | 230 | |
231 | - $this->value = $values; |
|
232 | - } |
|
231 | + $this->value = $values; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * Returns the type of value. |
|
236 | - * |
|
237 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
238 | - * 'default' valueType. |
|
239 | - * |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function getValueType() |
|
243 | - { |
|
244 | - return $this->hasTime() ? 'DATE-TIME' : 'DATE'; |
|
245 | - } |
|
234 | + /** |
|
235 | + * Returns the type of value. |
|
236 | + * |
|
237 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
238 | + * 'default' valueType. |
|
239 | + * |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function getValueType() |
|
243 | + { |
|
244 | + return $this->hasTime() ? 'DATE-TIME' : 'DATE'; |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Returns the value, in the format it should be encoded for JSON. |
|
249 | - * |
|
250 | - * This method must always return an array. |
|
251 | - * |
|
252 | - * @return array |
|
253 | - */ |
|
254 | - public function getJsonValue() |
|
255 | - { |
|
256 | - $dts = $this->getDateTimes(); |
|
257 | - $hasTime = $this->hasTime(); |
|
258 | - $isFloating = $this->isFloating(); |
|
247 | + /** |
|
248 | + * Returns the value, in the format it should be encoded for JSON. |
|
249 | + * |
|
250 | + * This method must always return an array. |
|
251 | + * |
|
252 | + * @return array |
|
253 | + */ |
|
254 | + public function getJsonValue() |
|
255 | + { |
|
256 | + $dts = $this->getDateTimes(); |
|
257 | + $hasTime = $this->hasTime(); |
|
258 | + $isFloating = $this->isFloating(); |
|
259 | 259 | |
260 | - $tz = $dts[0]->getTimeZone(); |
|
261 | - $isUtc = $isFloating ? false : in_array($tz->getName(), ['UTC', 'GMT', 'Z']); |
|
260 | + $tz = $dts[0]->getTimeZone(); |
|
261 | + $isUtc = $isFloating ? false : in_array($tz->getName(), ['UTC', 'GMT', 'Z']); |
|
262 | 262 | |
263 | - return array_map( |
|
264 | - function (DateTimeInterface $dt) use ($hasTime, $isUtc) { |
|
265 | - if ($hasTime) { |
|
266 | - return $dt->format('Y-m-d\\TH:i:s').($isUtc ? 'Z' : ''); |
|
267 | - } else { |
|
268 | - return $dt->format('Y-m-d'); |
|
269 | - } |
|
270 | - }, |
|
271 | - $dts |
|
272 | - ); |
|
273 | - } |
|
263 | + return array_map( |
|
264 | + function (DateTimeInterface $dt) use ($hasTime, $isUtc) { |
|
265 | + if ($hasTime) { |
|
266 | + return $dt->format('Y-m-d\\TH:i:s').($isUtc ? 'Z' : ''); |
|
267 | + } else { |
|
268 | + return $dt->format('Y-m-d'); |
|
269 | + } |
|
270 | + }, |
|
271 | + $dts |
|
272 | + ); |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * Sets the json value, as it would appear in a jCard or jCal object. |
|
277 | - * |
|
278 | - * The value must always be an array. |
|
279 | - */ |
|
280 | - public function setJsonValue(array $value) |
|
281 | - { |
|
282 | - // dates and times in jCal have one difference to dates and times in |
|
283 | - // iCalendar. In jCal date-parts are separated by dashes, and |
|
284 | - // time-parts are separated by colons. It makes sense to just remove |
|
285 | - // those. |
|
286 | - $this->setValue( |
|
287 | - array_map( |
|
288 | - function ($item) { |
|
289 | - return strtr($item, [':' => '', '-' => '']); |
|
290 | - }, |
|
291 | - $value |
|
292 | - ) |
|
293 | - ); |
|
294 | - } |
|
275 | + /** |
|
276 | + * Sets the json value, as it would appear in a jCard or jCal object. |
|
277 | + * |
|
278 | + * The value must always be an array. |
|
279 | + */ |
|
280 | + public function setJsonValue(array $value) |
|
281 | + { |
|
282 | + // dates and times in jCal have one difference to dates and times in |
|
283 | + // iCalendar. In jCal date-parts are separated by dashes, and |
|
284 | + // time-parts are separated by colons. It makes sense to just remove |
|
285 | + // those. |
|
286 | + $this->setValue( |
|
287 | + array_map( |
|
288 | + function ($item) { |
|
289 | + return strtr($item, [':' => '', '-' => '']); |
|
290 | + }, |
|
291 | + $value |
|
292 | + ) |
|
293 | + ); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * We need to intercept offsetSet, because it may be used to alter the |
|
298 | - * VALUE from DATE-TIME to DATE or vice-versa. |
|
299 | - * |
|
300 | - * @param string $name |
|
301 | - * @param mixed $value |
|
302 | - */ |
|
303 | - #[\ReturnTypeWillChange] |
|
304 | - public function offsetSet($name, $value) |
|
305 | - { |
|
306 | - parent::offsetSet($name, $value); |
|
307 | - if ('VALUE' !== strtoupper($name)) { |
|
308 | - return; |
|
309 | - } |
|
296 | + /** |
|
297 | + * We need to intercept offsetSet, because it may be used to alter the |
|
298 | + * VALUE from DATE-TIME to DATE or vice-versa. |
|
299 | + * |
|
300 | + * @param string $name |
|
301 | + * @param mixed $value |
|
302 | + */ |
|
303 | + #[\ReturnTypeWillChange] |
|
304 | + public function offsetSet($name, $value) |
|
305 | + { |
|
306 | + parent::offsetSet($name, $value); |
|
307 | + if ('VALUE' !== strtoupper($name)) { |
|
308 | + return; |
|
309 | + } |
|
310 | 310 | |
311 | - // This will ensure that dates are correctly encoded. |
|
312 | - $this->setDateTimes($this->getDateTimes()); |
|
313 | - } |
|
311 | + // This will ensure that dates are correctly encoded. |
|
312 | + $this->setDateTimes($this->getDateTimes()); |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Validates the node for correctness. |
|
317 | - * |
|
318 | - * The following options are supported: |
|
319 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
320 | - * |
|
321 | - * This method returns an array with detected problems. |
|
322 | - * Every element has the following properties: |
|
323 | - * |
|
324 | - * * level - problem level. |
|
325 | - * * message - A human-readable string describing the issue. |
|
326 | - * * node - A reference to the problematic node. |
|
327 | - * |
|
328 | - * The level means: |
|
329 | - * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
330 | - * 2 - An inconsequential issue |
|
331 | - * 3 - A severe issue. |
|
332 | - * |
|
333 | - * @param int $options |
|
334 | - * |
|
335 | - * @return array |
|
336 | - */ |
|
337 | - public function validate($options = 0) |
|
338 | - { |
|
339 | - $messages = parent::validate($options); |
|
340 | - $valueType = $this->getValueType(); |
|
341 | - $values = $this->getParts(); |
|
342 | - foreach ($values as $value) { |
|
343 | - try { |
|
344 | - switch ($valueType) { |
|
345 | - case 'DATE': |
|
346 | - DateTimeParser::parseDate($value); |
|
347 | - break; |
|
348 | - case 'DATE-TIME': |
|
349 | - DateTimeParser::parseDateTime($value); |
|
350 | - break; |
|
351 | - } |
|
352 | - } catch (InvalidDataException $e) { |
|
353 | - $messages[] = [ |
|
354 | - 'level' => 3, |
|
355 | - 'message' => 'The supplied value ('.$value.') is not a correct '.$valueType, |
|
356 | - 'node' => $this, |
|
357 | - ]; |
|
358 | - break; |
|
359 | - } |
|
360 | - } |
|
315 | + /** |
|
316 | + * Validates the node for correctness. |
|
317 | + * |
|
318 | + * The following options are supported: |
|
319 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
320 | + * |
|
321 | + * This method returns an array with detected problems. |
|
322 | + * Every element has the following properties: |
|
323 | + * |
|
324 | + * * level - problem level. |
|
325 | + * * message - A human-readable string describing the issue. |
|
326 | + * * node - A reference to the problematic node. |
|
327 | + * |
|
328 | + * The level means: |
|
329 | + * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
330 | + * 2 - An inconsequential issue |
|
331 | + * 3 - A severe issue. |
|
332 | + * |
|
333 | + * @param int $options |
|
334 | + * |
|
335 | + * @return array |
|
336 | + */ |
|
337 | + public function validate($options = 0) |
|
338 | + { |
|
339 | + $messages = parent::validate($options); |
|
340 | + $valueType = $this->getValueType(); |
|
341 | + $values = $this->getParts(); |
|
342 | + foreach ($values as $value) { |
|
343 | + try { |
|
344 | + switch ($valueType) { |
|
345 | + case 'DATE': |
|
346 | + DateTimeParser::parseDate($value); |
|
347 | + break; |
|
348 | + case 'DATE-TIME': |
|
349 | + DateTimeParser::parseDateTime($value); |
|
350 | + break; |
|
351 | + } |
|
352 | + } catch (InvalidDataException $e) { |
|
353 | + $messages[] = [ |
|
354 | + 'level' => 3, |
|
355 | + 'message' => 'The supplied value ('.$value.') is not a correct '.$valueType, |
|
356 | + 'node' => $this, |
|
357 | + ]; |
|
358 | + break; |
|
359 | + } |
|
360 | + } |
|
361 | 361 | |
362 | - return $messages; |
|
363 | - } |
|
362 | + return $messages; |
|
363 | + } |
|
364 | 364 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $isUtc = $isFloating ? false : in_array($tz->getName(), ['UTC', 'GMT', 'Z']); |
262 | 262 | |
263 | 263 | return array_map( |
264 | - function (DateTimeInterface $dt) use ($hasTime, $isUtc) { |
|
264 | + function(DateTimeInterface $dt) use ($hasTime, $isUtc) { |
|
265 | 265 | if ($hasTime) { |
266 | 266 | return $dt->format('Y-m-d\\TH:i:s').($isUtc ? 'Z' : ''); |
267 | 267 | } else { |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | // those. |
286 | 286 | $this->setValue( |
287 | 287 | array_map( |
288 | - function ($item) { |
|
288 | + function($item) { |
|
289 | 289 | return strtr($item, [':' => '', '-' => '']); |
290 | 290 | }, |
291 | 291 | $value |
@@ -18,55 +18,55 @@ |
||
18 | 18 | */ |
19 | 19 | class Boolean extends Property |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
23 | - * |
|
24 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
25 | - * not yet done, but parameters are not included. |
|
26 | - * |
|
27 | - * @param string $val |
|
28 | - */ |
|
29 | - public function setRawMimeDirValue($val) |
|
30 | - { |
|
31 | - $val = 'TRUE' === strtoupper($val) ? true : false; |
|
32 | - $this->setValue($val); |
|
33 | - } |
|
21 | + /** |
|
22 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
23 | + * |
|
24 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
25 | + * not yet done, but parameters are not included. |
|
26 | + * |
|
27 | + * @param string $val |
|
28 | + */ |
|
29 | + public function setRawMimeDirValue($val) |
|
30 | + { |
|
31 | + $val = 'TRUE' === strtoupper($val) ? true : false; |
|
32 | + $this->setValue($val); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns a raw mime-dir representation of the value. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getRawMimeDirValue() |
|
41 | - { |
|
42 | - return $this->value ? 'TRUE' : 'FALSE'; |
|
43 | - } |
|
35 | + /** |
|
36 | + * Returns a raw mime-dir representation of the value. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getRawMimeDirValue() |
|
41 | + { |
|
42 | + return $this->value ? 'TRUE' : 'FALSE'; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the type of value. |
|
47 | - * |
|
48 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
49 | - * 'default' valueType. |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function getValueType() |
|
54 | - { |
|
55 | - return 'BOOLEAN'; |
|
56 | - } |
|
45 | + /** |
|
46 | + * Returns the type of value. |
|
47 | + * |
|
48 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
49 | + * 'default' valueType. |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function getValueType() |
|
54 | + { |
|
55 | + return 'BOOLEAN'; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
60 | - * object. |
|
61 | - */ |
|
62 | - public function setXmlValue(array $value) |
|
63 | - { |
|
64 | - $value = array_map( |
|
65 | - function ($value) { |
|
66 | - return 'true' === $value; |
|
67 | - }, |
|
68 | - $value |
|
69 | - ); |
|
70 | - parent::setXmlValue($value); |
|
71 | - } |
|
58 | + /** |
|
59 | + * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
60 | + * object. |
|
61 | + */ |
|
62 | + public function setXmlValue(array $value) |
|
63 | + { |
|
64 | + $value = array_map( |
|
65 | + function ($value) { |
|
66 | + return 'true' === $value; |
|
67 | + }, |
|
68 | + $value |
|
69 | + ); |
|
70 | + parent::setXmlValue($value); |
|
71 | + } |
|
72 | 72 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | public function setXmlValue(array $value) |
63 | 63 | { |
64 | 64 | $value = array_map( |
65 | - function ($value) { |
|
65 | + function($value) { |
|
66 | 66 | return 'true' === $value; |
67 | 67 | }, |
68 | 68 | $value |
@@ -15,117 +15,117 @@ |
||
15 | 15 | */ |
16 | 16 | class Time extends Text |
17 | 17 | { |
18 | - /** |
|
19 | - * In case this is a multi-value property. This string will be used as a |
|
20 | - * delimiter. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $delimiter = ''; |
|
18 | + /** |
|
19 | + * In case this is a multi-value property. This string will be used as a |
|
20 | + * delimiter. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $delimiter = ''; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the type of value. |
|
28 | - * |
|
29 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
30 | - * 'default' valueType. |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getValueType() |
|
35 | - { |
|
36 | - return 'TIME'; |
|
37 | - } |
|
26 | + /** |
|
27 | + * Returns the type of value. |
|
28 | + * |
|
29 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
30 | + * 'default' valueType. |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getValueType() |
|
35 | + { |
|
36 | + return 'TIME'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Sets the JSON value, as it would appear in a jCard or jCal object. |
|
41 | - * |
|
42 | - * The value must always be an array. |
|
43 | - */ |
|
44 | - public function setJsonValue(array $value) |
|
45 | - { |
|
46 | - // Removing colons from value. |
|
47 | - $value = str_replace( |
|
48 | - ':', |
|
49 | - '', |
|
50 | - $value |
|
51 | - ); |
|
39 | + /** |
|
40 | + * Sets the JSON value, as it would appear in a jCard or jCal object. |
|
41 | + * |
|
42 | + * The value must always be an array. |
|
43 | + */ |
|
44 | + public function setJsonValue(array $value) |
|
45 | + { |
|
46 | + // Removing colons from value. |
|
47 | + $value = str_replace( |
|
48 | + ':', |
|
49 | + '', |
|
50 | + $value |
|
51 | + ); |
|
52 | 52 | |
53 | - if (1 === count($value)) { |
|
54 | - $this->setValue(reset($value)); |
|
55 | - } else { |
|
56 | - $this->setValue($value); |
|
57 | - } |
|
58 | - } |
|
53 | + if (1 === count($value)) { |
|
54 | + $this->setValue(reset($value)); |
|
55 | + } else { |
|
56 | + $this->setValue($value); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns the value, in the format it should be encoded for json. |
|
62 | - * |
|
63 | - * This method must always return an array. |
|
64 | - * |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function getJsonValue() |
|
68 | - { |
|
69 | - $parts = DateTimeParser::parseVCardTime($this->getValue()); |
|
70 | - $timeStr = ''; |
|
60 | + /** |
|
61 | + * Returns the value, in the format it should be encoded for json. |
|
62 | + * |
|
63 | + * This method must always return an array. |
|
64 | + * |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function getJsonValue() |
|
68 | + { |
|
69 | + $parts = DateTimeParser::parseVCardTime($this->getValue()); |
|
70 | + $timeStr = ''; |
|
71 | 71 | |
72 | - // Hour |
|
73 | - if (!is_null($parts['hour'])) { |
|
74 | - $timeStr .= $parts['hour']; |
|
72 | + // Hour |
|
73 | + if (!is_null($parts['hour'])) { |
|
74 | + $timeStr .= $parts['hour']; |
|
75 | 75 | |
76 | - if (!is_null($parts['minute'])) { |
|
77 | - $timeStr .= ':'; |
|
78 | - } |
|
79 | - } else { |
|
80 | - // We know either minute or second _must_ be set, so we insert a |
|
81 | - // dash for an empty value. |
|
82 | - $timeStr .= '-'; |
|
83 | - } |
|
76 | + if (!is_null($parts['minute'])) { |
|
77 | + $timeStr .= ':'; |
|
78 | + } |
|
79 | + } else { |
|
80 | + // We know either minute or second _must_ be set, so we insert a |
|
81 | + // dash for an empty value. |
|
82 | + $timeStr .= '-'; |
|
83 | + } |
|
84 | 84 | |
85 | - // Minute |
|
86 | - if (!is_null($parts['minute'])) { |
|
87 | - $timeStr .= $parts['minute']; |
|
85 | + // Minute |
|
86 | + if (!is_null($parts['minute'])) { |
|
87 | + $timeStr .= $parts['minute']; |
|
88 | 88 | |
89 | - if (!is_null($parts['second'])) { |
|
90 | - $timeStr .= ':'; |
|
91 | - } |
|
92 | - } else { |
|
93 | - if (isset($parts['second'])) { |
|
94 | - // Dash for empty minute |
|
95 | - $timeStr .= '-'; |
|
96 | - } |
|
97 | - } |
|
89 | + if (!is_null($parts['second'])) { |
|
90 | + $timeStr .= ':'; |
|
91 | + } |
|
92 | + } else { |
|
93 | + if (isset($parts['second'])) { |
|
94 | + // Dash for empty minute |
|
95 | + $timeStr .= '-'; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - // Second |
|
100 | - if (!is_null($parts['second'])) { |
|
101 | - $timeStr .= $parts['second']; |
|
102 | - } |
|
99 | + // Second |
|
100 | + if (!is_null($parts['second'])) { |
|
101 | + $timeStr .= $parts['second']; |
|
102 | + } |
|
103 | 103 | |
104 | - // Timezone |
|
105 | - if (!is_null($parts['timezone'])) { |
|
106 | - if ('Z' === $parts['timezone']) { |
|
107 | - $timeStr .= 'Z'; |
|
108 | - } else { |
|
109 | - $timeStr .= |
|
110 | - preg_replace('/([0-9]{2})([0-9]{2})$/', '$1:$2', $parts['timezone']); |
|
111 | - } |
|
112 | - } |
|
104 | + // Timezone |
|
105 | + if (!is_null($parts['timezone'])) { |
|
106 | + if ('Z' === $parts['timezone']) { |
|
107 | + $timeStr .= 'Z'; |
|
108 | + } else { |
|
109 | + $timeStr .= |
|
110 | + preg_replace('/([0-9]{2})([0-9]{2})$/', '$1:$2', $parts['timezone']); |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - return [$timeStr]; |
|
115 | - } |
|
114 | + return [$timeStr]; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
119 | - * object. |
|
120 | - */ |
|
121 | - public function setXmlValue(array $value) |
|
122 | - { |
|
123 | - $value = array_map( |
|
124 | - function ($value) { |
|
125 | - return str_replace(':', '', $value); |
|
126 | - }, |
|
127 | - $value |
|
128 | - ); |
|
129 | - parent::setXmlValue($value); |
|
130 | - } |
|
117 | + /** |
|
118 | + * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
119 | + * object. |
|
120 | + */ |
|
121 | + public function setXmlValue(array $value) |
|
122 | + { |
|
123 | + $value = array_map( |
|
124 | + function ($value) { |
|
125 | + return str_replace(':', '', $value); |
|
126 | + }, |
|
127 | + $value |
|
128 | + ); |
|
129 | + parent::setXmlValue($value); |
|
130 | + } |
|
131 | 131 | } |
@@ -121,7 +121,7 @@ |
||
121 | 121 | public function setXmlValue(array $value) |
122 | 122 | { |
123 | 123 | $value = array_map( |
124 | - function ($value) { |
|
124 | + function($value) { |
|
125 | 125 | return str_replace(':', '', $value); |
126 | 126 | }, |
127 | 127 | $value |
@@ -17,65 +17,65 @@ |
||
17 | 17 | */ |
18 | 18 | class TimeStamp extends Text |
19 | 19 | { |
20 | - /** |
|
21 | - * In case this is a multi-value property. This string will be used as a |
|
22 | - * delimiter. |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - public $delimiter = ''; |
|
20 | + /** |
|
21 | + * In case this is a multi-value property. This string will be used as a |
|
22 | + * delimiter. |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + public $delimiter = ''; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Returns the type of value. |
|
30 | - * |
|
31 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
32 | - * 'default' valueType. |
|
33 | - * |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getValueType() |
|
37 | - { |
|
38 | - return 'TIMESTAMP'; |
|
39 | - } |
|
28 | + /** |
|
29 | + * Returns the type of value. |
|
30 | + * |
|
31 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
32 | + * 'default' valueType. |
|
33 | + * |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getValueType() |
|
37 | + { |
|
38 | + return 'TIMESTAMP'; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the value, in the format it should be encoded for json. |
|
43 | - * |
|
44 | - * This method must always return an array. |
|
45 | - * |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getJsonValue() |
|
49 | - { |
|
50 | - $parts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
41 | + /** |
|
42 | + * Returns the value, in the format it should be encoded for json. |
|
43 | + * |
|
44 | + * This method must always return an array. |
|
45 | + * |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getJsonValue() |
|
49 | + { |
|
50 | + $parts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
51 | 51 | |
52 | - $dateStr = |
|
53 | - $parts['year'].'-'. |
|
54 | - $parts['month'].'-'. |
|
55 | - $parts['date'].'T'. |
|
56 | - $parts['hour'].':'. |
|
57 | - $parts['minute'].':'. |
|
58 | - $parts['second']; |
|
52 | + $dateStr = |
|
53 | + $parts['year'].'-'. |
|
54 | + $parts['month'].'-'. |
|
55 | + $parts['date'].'T'. |
|
56 | + $parts['hour'].':'. |
|
57 | + $parts['minute'].':'. |
|
58 | + $parts['second']; |
|
59 | 59 | |
60 | - // Timezone |
|
61 | - if (!is_null($parts['timezone'])) { |
|
62 | - $dateStr .= $parts['timezone']; |
|
63 | - } |
|
60 | + // Timezone |
|
61 | + if (!is_null($parts['timezone'])) { |
|
62 | + $dateStr .= $parts['timezone']; |
|
63 | + } |
|
64 | 64 | |
65 | - return [$dateStr]; |
|
66 | - } |
|
65 | + return [$dateStr]; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * This method serializes only the value of a property. This is used to |
|
70 | - * create xCard or xCal documents. |
|
71 | - * |
|
72 | - * @param Xml\Writer $writer XML writer |
|
73 | - */ |
|
74 | - protected function xmlSerializeValue(Xml\Writer $writer) |
|
75 | - { |
|
76 | - // xCard is the only XML and JSON format that has the same date and time |
|
77 | - // format than vCard. |
|
78 | - $valueType = strtolower($this->getValueType()); |
|
79 | - $writer->writeElement($valueType, $this->getValue()); |
|
80 | - } |
|
68 | + /** |
|
69 | + * This method serializes only the value of a property. This is used to |
|
70 | + * create xCard or xCal documents. |
|
71 | + * |
|
72 | + * @param Xml\Writer $writer XML writer |
|
73 | + */ |
|
74 | + protected function xmlSerializeValue(Xml\Writer $writer) |
|
75 | + { |
|
76 | + // xCard is the only XML and JSON format that has the same date and time |
|
77 | + // format than vCard. |
|
78 | + $valueType = strtolower($this->getValueType()); |
|
79 | + $writer->writeElement($valueType, $this->getValue()); |
|
80 | + } |
|
81 | 81 | } |
@@ -13,24 +13,24 @@ |
||
13 | 13 | */ |
14 | 14 | class Date extends DateAndOrTime |
15 | 15 | { |
16 | - /** |
|
17 | - * Returns the type of value. |
|
18 | - * |
|
19 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
20 | - * 'default' valueType. |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function getValueType() |
|
25 | - { |
|
26 | - return 'DATE'; |
|
27 | - } |
|
16 | + /** |
|
17 | + * Returns the type of value. |
|
18 | + * |
|
19 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
20 | + * 'default' valueType. |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function getValueType() |
|
25 | + { |
|
26 | + return 'DATE'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Sets the property as a DateTime object. |
|
31 | - */ |
|
32 | - public function setDateTime(\DateTimeInterface $dt) |
|
33 | - { |
|
34 | - $this->value = $dt->format('Ymd'); |
|
35 | - } |
|
29 | + /** |
|
30 | + * Sets the property as a DateTime object. |
|
31 | + */ |
|
32 | + public function setDateTime(\DateTimeInterface $dt) |
|
33 | + { |
|
34 | + $this->value = $dt->format('Ymd'); |
|
35 | + } |
|
36 | 36 | } |
@@ -21,347 +21,347 @@ |
||
21 | 21 | */ |
22 | 22 | class DateAndOrTime extends Property |
23 | 23 | { |
24 | - /** |
|
25 | - * Field separator. |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $delimiter = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * Returns the type of value. |
|
33 | - * |
|
34 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
35 | - * 'default' valueType. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getValueType() |
|
40 | - { |
|
41 | - return 'DATE-AND-OR-TIME'; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Sets a multi-valued property. |
|
46 | - * |
|
47 | - * You may also specify DateTimeInterface objects here. |
|
48 | - */ |
|
49 | - public function setParts(array $parts) |
|
50 | - { |
|
51 | - if (count($parts) > 1) { |
|
52 | - throw new \InvalidArgumentException('Only one value allowed'); |
|
53 | - } |
|
54 | - if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { |
|
55 | - $this->setDateTime($parts[0]); |
|
56 | - } else { |
|
57 | - parent::setParts($parts); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Updates the current value. |
|
63 | - * |
|
64 | - * This may be either a single, or multiple strings in an array. |
|
65 | - * |
|
66 | - * Instead of strings, you may also use DateTimeInterface here. |
|
67 | - * |
|
68 | - * @param string|array|DateTimeInterface $value |
|
69 | - */ |
|
70 | - public function setValue($value) |
|
71 | - { |
|
72 | - if ($value instanceof DateTimeInterface) { |
|
73 | - $this->setDateTime($value); |
|
74 | - } else { |
|
75 | - parent::setValue($value); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets the property as a DateTime object. |
|
81 | - */ |
|
82 | - public function setDateTime(DateTimeInterface $dt) |
|
83 | - { |
|
84 | - $tz = $dt->getTimeZone(); |
|
85 | - $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']); |
|
86 | - |
|
87 | - if ($isUtc) { |
|
88 | - $value = $dt->format('Ymd\\THis\\Z'); |
|
89 | - } else { |
|
90 | - // Calculating the offset. |
|
91 | - $value = $dt->format('Ymd\\THisO'); |
|
92 | - } |
|
93 | - |
|
94 | - $this->value = $value; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns a date-time value. |
|
99 | - * |
|
100 | - * Note that if this property contained more than 1 date-time, only the |
|
101 | - * first will be returned. To get an array with multiple values, call |
|
102 | - * getDateTimes. |
|
103 | - * |
|
104 | - * If no time was specified, we will always use midnight (in the default |
|
105 | - * timezone) as the time. |
|
106 | - * |
|
107 | - * If parts of the date were omitted, such as the year, we will grab the |
|
108 | - * current values for those. So at the time of writing, if the year was |
|
109 | - * omitted, we would have filled in 2014. |
|
110 | - * |
|
111 | - * @return DateTimeImmutable |
|
112 | - */ |
|
113 | - public function getDateTime() |
|
114 | - { |
|
115 | - $now = new DateTime(); |
|
116 | - |
|
117 | - $tzFormat = 0 === $now->getTimezone()->getOffset($now) ? '\\Z' : 'O'; |
|
118 | - $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This'.$tzFormat)); |
|
119 | - |
|
120 | - $dateParts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
121 | - |
|
122 | - // This sets all the missing parts to the current date/time. |
|
123 | - // So if the year was missing for a birthday, we're making it 'this |
|
124 | - // year'. |
|
125 | - foreach ($dateParts as $k => $v) { |
|
126 | - if (is_null($v)) { |
|
127 | - $dateParts[$k] = $nowParts[$k]; |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]"); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns the value, in the format it should be encoded for json. |
|
136 | - * |
|
137 | - * This method must always return an array. |
|
138 | - * |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public function getJsonValue() |
|
142 | - { |
|
143 | - $parts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
144 | - |
|
145 | - $dateStr = ''; |
|
146 | - |
|
147 | - // Year |
|
148 | - if (!is_null($parts['year'])) { |
|
149 | - $dateStr .= $parts['year']; |
|
150 | - |
|
151 | - if (!is_null($parts['month'])) { |
|
152 | - // If a year and a month is set, we need to insert a separator |
|
153 | - // dash. |
|
154 | - $dateStr .= '-'; |
|
155 | - } |
|
156 | - } else { |
|
157 | - if (!is_null($parts['month']) || !is_null($parts['date'])) { |
|
158 | - // Inserting two dashes |
|
159 | - $dateStr .= '--'; |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - // Month |
|
164 | - if (!is_null($parts['month'])) { |
|
165 | - $dateStr .= $parts['month']; |
|
166 | - |
|
167 | - if (isset($parts['date'])) { |
|
168 | - // If month and date are set, we need the separator dash. |
|
169 | - $dateStr .= '-'; |
|
170 | - } |
|
171 | - } elseif (isset($parts['date'])) { |
|
172 | - // If the month is empty, and a date is set, we need a 'empty |
|
173 | - // dash' |
|
174 | - $dateStr .= '-'; |
|
175 | - } |
|
176 | - |
|
177 | - // Date |
|
178 | - if (!is_null($parts['date'])) { |
|
179 | - $dateStr .= $parts['date']; |
|
180 | - } |
|
181 | - |
|
182 | - // Early exit if we don't have a time string. |
|
183 | - if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) { |
|
184 | - return [$dateStr]; |
|
185 | - } |
|
186 | - |
|
187 | - $dateStr .= 'T'; |
|
188 | - |
|
189 | - // Hour |
|
190 | - if (!is_null($parts['hour'])) { |
|
191 | - $dateStr .= $parts['hour']; |
|
192 | - |
|
193 | - if (!is_null($parts['minute'])) { |
|
194 | - $dateStr .= ':'; |
|
195 | - } |
|
196 | - } else { |
|
197 | - // We know either minute or second _must_ be set, so we insert a |
|
198 | - // dash for an empty value. |
|
199 | - $dateStr .= '-'; |
|
200 | - } |
|
201 | - |
|
202 | - // Minute |
|
203 | - if (!is_null($parts['minute'])) { |
|
204 | - $dateStr .= $parts['minute']; |
|
205 | - |
|
206 | - if (!is_null($parts['second'])) { |
|
207 | - $dateStr .= ':'; |
|
208 | - } |
|
209 | - } elseif (isset($parts['second'])) { |
|
210 | - // Dash for empty minute |
|
211 | - $dateStr .= '-'; |
|
212 | - } |
|
213 | - |
|
214 | - // Second |
|
215 | - if (!is_null($parts['second'])) { |
|
216 | - $dateStr .= $parts['second']; |
|
217 | - } |
|
218 | - |
|
219 | - // Timezone |
|
220 | - if (!is_null($parts['timezone'])) { |
|
221 | - $dateStr .= $parts['timezone']; |
|
222 | - } |
|
223 | - |
|
224 | - return [$dateStr]; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * This method serializes only the value of a property. This is used to |
|
229 | - * create xCard or xCal documents. |
|
230 | - * |
|
231 | - * @param Xml\Writer $writer XML writer |
|
232 | - */ |
|
233 | - protected function xmlSerializeValue(Xml\Writer $writer) |
|
234 | - { |
|
235 | - $valueType = strtolower($this->getValueType()); |
|
236 | - $parts = DateTimeParser::parseVCardDateAndOrTime($this->getValue()); |
|
237 | - $value = ''; |
|
238 | - |
|
239 | - // $d = defined |
|
240 | - $d = function ($part) use ($parts) { |
|
241 | - return !is_null($parts[$part]); |
|
242 | - }; |
|
243 | - |
|
244 | - // $r = read |
|
245 | - $r = function ($part) use ($parts) { |
|
246 | - return $parts[$part]; |
|
247 | - }; |
|
248 | - |
|
249 | - // From the Relax NG Schema. |
|
250 | - // |
|
251 | - // # 4.3.1 |
|
252 | - // value-date = element date { |
|
253 | - // xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" } |
|
254 | - // } |
|
255 | - if (($d('year') || $d('month') || $d('date')) |
|
256 | - && (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) { |
|
257 | - if ($d('year') && $d('month') && $d('date')) { |
|
258 | - $value .= $r('year').$r('month').$r('date'); |
|
259 | - } elseif ($d('year') && $d('month') && !$d('date')) { |
|
260 | - $value .= $r('year').'-'.$r('month'); |
|
261 | - } elseif (!$d('year') && $d('month')) { |
|
262 | - $value .= '--'.$r('month').$r('date'); |
|
263 | - } elseif (!$d('year') && !$d('month') && $d('date')) { |
|
264 | - $value .= '---'.$r('date'); |
|
265 | - } |
|
266 | - |
|
267 | - // # 4.3.2 |
|
268 | - // value-time = element time { |
|
269 | - // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" |
|
270 | - // ~ "(Z|[+\-]\d\d(\d\d)?)?" } |
|
271 | - // } |
|
272 | - } elseif ((!$d('year') && !$d('month') && !$d('date')) |
|
273 | - && ($d('hour') || $d('minute') || $d('second'))) { |
|
274 | - if ($d('hour')) { |
|
275 | - $value .= $r('hour').$r('minute').$r('second'); |
|
276 | - } elseif ($d('minute')) { |
|
277 | - $value .= '-'.$r('minute').$r('second'); |
|
278 | - } elseif ($d('second')) { |
|
279 | - $value .= '--'.$r('second'); |
|
280 | - } |
|
281 | - |
|
282 | - $value .= $r('timezone'); |
|
283 | - |
|
284 | - // # 4.3.3 |
|
285 | - // value-date-time = element date-time { |
|
286 | - // xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?" |
|
287 | - // ~ "(Z|[+\-]\d\d(\d\d)?)?" } |
|
288 | - // } |
|
289 | - } elseif ($d('date') && $d('hour')) { |
|
290 | - if ($d('year') && $d('month') && $d('date')) { |
|
291 | - $value .= $r('year').$r('month').$r('date'); |
|
292 | - } elseif (!$d('year') && $d('month') && $d('date')) { |
|
293 | - $value .= '--'.$r('month').$r('date'); |
|
294 | - } elseif (!$d('year') && !$d('month') && $d('date')) { |
|
295 | - $value .= '---'.$r('date'); |
|
296 | - } |
|
297 | - |
|
298 | - $value .= 'T'.$r('hour').$r('minute').$r('second'). |
|
299 | - $r('timezone'); |
|
300 | - } |
|
301 | - |
|
302 | - $writer->writeElement($valueType, $value); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
307 | - * |
|
308 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
309 | - * not yet done, but parameters are not included. |
|
310 | - * |
|
311 | - * @param string $val |
|
312 | - */ |
|
313 | - public function setRawMimeDirValue($val) |
|
314 | - { |
|
315 | - $this->setValue($val); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns a raw mime-dir representation of the value. |
|
320 | - * |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - public function getRawMimeDirValue() |
|
324 | - { |
|
325 | - return implode($this->delimiter, $this->getParts()); |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Validates the node for correctness. |
|
330 | - * |
|
331 | - * The following options are supported: |
|
332 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
333 | - * |
|
334 | - * This method returns an array with detected problems. |
|
335 | - * Every element has the following properties: |
|
336 | - * |
|
337 | - * * level - problem level. |
|
338 | - * * message - A human-readable string describing the issue. |
|
339 | - * * node - A reference to the problematic node. |
|
340 | - * |
|
341 | - * The level means: |
|
342 | - * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
343 | - * 2 - An inconsequential issue |
|
344 | - * 3 - A severe issue. |
|
345 | - * |
|
346 | - * @param int $options |
|
347 | - * |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - public function validate($options = 0) |
|
351 | - { |
|
352 | - $messages = parent::validate($options); |
|
353 | - $value = $this->getValue(); |
|
354 | - |
|
355 | - try { |
|
356 | - DateTimeParser::parseVCardDateTime($value); |
|
357 | - } catch (InvalidDataException $e) { |
|
358 | - $messages[] = [ |
|
359 | - 'level' => 3, |
|
360 | - 'message' => 'The supplied value ('.$value.') is not a correct DATE-AND-OR-TIME property', |
|
361 | - 'node' => $this, |
|
362 | - ]; |
|
363 | - } |
|
364 | - |
|
365 | - return $messages; |
|
366 | - } |
|
24 | + /** |
|
25 | + * Field separator. |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $delimiter = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * Returns the type of value. |
|
33 | + * |
|
34 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
35 | + * 'default' valueType. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getValueType() |
|
40 | + { |
|
41 | + return 'DATE-AND-OR-TIME'; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Sets a multi-valued property. |
|
46 | + * |
|
47 | + * You may also specify DateTimeInterface objects here. |
|
48 | + */ |
|
49 | + public function setParts(array $parts) |
|
50 | + { |
|
51 | + if (count($parts) > 1) { |
|
52 | + throw new \InvalidArgumentException('Only one value allowed'); |
|
53 | + } |
|
54 | + if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { |
|
55 | + $this->setDateTime($parts[0]); |
|
56 | + } else { |
|
57 | + parent::setParts($parts); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Updates the current value. |
|
63 | + * |
|
64 | + * This may be either a single, or multiple strings in an array. |
|
65 | + * |
|
66 | + * Instead of strings, you may also use DateTimeInterface here. |
|
67 | + * |
|
68 | + * @param string|array|DateTimeInterface $value |
|
69 | + */ |
|
70 | + public function setValue($value) |
|
71 | + { |
|
72 | + if ($value instanceof DateTimeInterface) { |
|
73 | + $this->setDateTime($value); |
|
74 | + } else { |
|
75 | + parent::setValue($value); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets the property as a DateTime object. |
|
81 | + */ |
|
82 | + public function setDateTime(DateTimeInterface $dt) |
|
83 | + { |
|
84 | + $tz = $dt->getTimeZone(); |
|
85 | + $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']); |
|
86 | + |
|
87 | + if ($isUtc) { |
|
88 | + $value = $dt->format('Ymd\\THis\\Z'); |
|
89 | + } else { |
|
90 | + // Calculating the offset. |
|
91 | + $value = $dt->format('Ymd\\THisO'); |
|
92 | + } |
|
93 | + |
|
94 | + $this->value = $value; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns a date-time value. |
|
99 | + * |
|
100 | + * Note that if this property contained more than 1 date-time, only the |
|
101 | + * first will be returned. To get an array with multiple values, call |
|
102 | + * getDateTimes. |
|
103 | + * |
|
104 | + * If no time was specified, we will always use midnight (in the default |
|
105 | + * timezone) as the time. |
|
106 | + * |
|
107 | + * If parts of the date were omitted, such as the year, we will grab the |
|
108 | + * current values for those. So at the time of writing, if the year was |
|
109 | + * omitted, we would have filled in 2014. |
|
110 | + * |
|
111 | + * @return DateTimeImmutable |
|
112 | + */ |
|
113 | + public function getDateTime() |
|
114 | + { |
|
115 | + $now = new DateTime(); |
|
116 | + |
|
117 | + $tzFormat = 0 === $now->getTimezone()->getOffset($now) ? '\\Z' : 'O'; |
|
118 | + $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This'.$tzFormat)); |
|
119 | + |
|
120 | + $dateParts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
121 | + |
|
122 | + // This sets all the missing parts to the current date/time. |
|
123 | + // So if the year was missing for a birthday, we're making it 'this |
|
124 | + // year'. |
|
125 | + foreach ($dateParts as $k => $v) { |
|
126 | + if (is_null($v)) { |
|
127 | + $dateParts[$k] = $nowParts[$k]; |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]"); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns the value, in the format it should be encoded for json. |
|
136 | + * |
|
137 | + * This method must always return an array. |
|
138 | + * |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public function getJsonValue() |
|
142 | + { |
|
143 | + $parts = DateTimeParser::parseVCardDateTime($this->getValue()); |
|
144 | + |
|
145 | + $dateStr = ''; |
|
146 | + |
|
147 | + // Year |
|
148 | + if (!is_null($parts['year'])) { |
|
149 | + $dateStr .= $parts['year']; |
|
150 | + |
|
151 | + if (!is_null($parts['month'])) { |
|
152 | + // If a year and a month is set, we need to insert a separator |
|
153 | + // dash. |
|
154 | + $dateStr .= '-'; |
|
155 | + } |
|
156 | + } else { |
|
157 | + if (!is_null($parts['month']) || !is_null($parts['date'])) { |
|
158 | + // Inserting two dashes |
|
159 | + $dateStr .= '--'; |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + // Month |
|
164 | + if (!is_null($parts['month'])) { |
|
165 | + $dateStr .= $parts['month']; |
|
166 | + |
|
167 | + if (isset($parts['date'])) { |
|
168 | + // If month and date are set, we need the separator dash. |
|
169 | + $dateStr .= '-'; |
|
170 | + } |
|
171 | + } elseif (isset($parts['date'])) { |
|
172 | + // If the month is empty, and a date is set, we need a 'empty |
|
173 | + // dash' |
|
174 | + $dateStr .= '-'; |
|
175 | + } |
|
176 | + |
|
177 | + // Date |
|
178 | + if (!is_null($parts['date'])) { |
|
179 | + $dateStr .= $parts['date']; |
|
180 | + } |
|
181 | + |
|
182 | + // Early exit if we don't have a time string. |
|
183 | + if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) { |
|
184 | + return [$dateStr]; |
|
185 | + } |
|
186 | + |
|
187 | + $dateStr .= 'T'; |
|
188 | + |
|
189 | + // Hour |
|
190 | + if (!is_null($parts['hour'])) { |
|
191 | + $dateStr .= $parts['hour']; |
|
192 | + |
|
193 | + if (!is_null($parts['minute'])) { |
|
194 | + $dateStr .= ':'; |
|
195 | + } |
|
196 | + } else { |
|
197 | + // We know either minute or second _must_ be set, so we insert a |
|
198 | + // dash for an empty value. |
|
199 | + $dateStr .= '-'; |
|
200 | + } |
|
201 | + |
|
202 | + // Minute |
|
203 | + if (!is_null($parts['minute'])) { |
|
204 | + $dateStr .= $parts['minute']; |
|
205 | + |
|
206 | + if (!is_null($parts['second'])) { |
|
207 | + $dateStr .= ':'; |
|
208 | + } |
|
209 | + } elseif (isset($parts['second'])) { |
|
210 | + // Dash for empty minute |
|
211 | + $dateStr .= '-'; |
|
212 | + } |
|
213 | + |
|
214 | + // Second |
|
215 | + if (!is_null($parts['second'])) { |
|
216 | + $dateStr .= $parts['second']; |
|
217 | + } |
|
218 | + |
|
219 | + // Timezone |
|
220 | + if (!is_null($parts['timezone'])) { |
|
221 | + $dateStr .= $parts['timezone']; |
|
222 | + } |
|
223 | + |
|
224 | + return [$dateStr]; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * This method serializes only the value of a property. This is used to |
|
229 | + * create xCard or xCal documents. |
|
230 | + * |
|
231 | + * @param Xml\Writer $writer XML writer |
|
232 | + */ |
|
233 | + protected function xmlSerializeValue(Xml\Writer $writer) |
|
234 | + { |
|
235 | + $valueType = strtolower($this->getValueType()); |
|
236 | + $parts = DateTimeParser::parseVCardDateAndOrTime($this->getValue()); |
|
237 | + $value = ''; |
|
238 | + |
|
239 | + // $d = defined |
|
240 | + $d = function ($part) use ($parts) { |
|
241 | + return !is_null($parts[$part]); |
|
242 | + }; |
|
243 | + |
|
244 | + // $r = read |
|
245 | + $r = function ($part) use ($parts) { |
|
246 | + return $parts[$part]; |
|
247 | + }; |
|
248 | + |
|
249 | + // From the Relax NG Schema. |
|
250 | + // |
|
251 | + // # 4.3.1 |
|
252 | + // value-date = element date { |
|
253 | + // xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" } |
|
254 | + // } |
|
255 | + if (($d('year') || $d('month') || $d('date')) |
|
256 | + && (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) { |
|
257 | + if ($d('year') && $d('month') && $d('date')) { |
|
258 | + $value .= $r('year').$r('month').$r('date'); |
|
259 | + } elseif ($d('year') && $d('month') && !$d('date')) { |
|
260 | + $value .= $r('year').'-'.$r('month'); |
|
261 | + } elseif (!$d('year') && $d('month')) { |
|
262 | + $value .= '--'.$r('month').$r('date'); |
|
263 | + } elseif (!$d('year') && !$d('month') && $d('date')) { |
|
264 | + $value .= '---'.$r('date'); |
|
265 | + } |
|
266 | + |
|
267 | + // # 4.3.2 |
|
268 | + // value-time = element time { |
|
269 | + // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" |
|
270 | + // ~ "(Z|[+\-]\d\d(\d\d)?)?" } |
|
271 | + // } |
|
272 | + } elseif ((!$d('year') && !$d('month') && !$d('date')) |
|
273 | + && ($d('hour') || $d('minute') || $d('second'))) { |
|
274 | + if ($d('hour')) { |
|
275 | + $value .= $r('hour').$r('minute').$r('second'); |
|
276 | + } elseif ($d('minute')) { |
|
277 | + $value .= '-'.$r('minute').$r('second'); |
|
278 | + } elseif ($d('second')) { |
|
279 | + $value .= '--'.$r('second'); |
|
280 | + } |
|
281 | + |
|
282 | + $value .= $r('timezone'); |
|
283 | + |
|
284 | + // # 4.3.3 |
|
285 | + // value-date-time = element date-time { |
|
286 | + // xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?" |
|
287 | + // ~ "(Z|[+\-]\d\d(\d\d)?)?" } |
|
288 | + // } |
|
289 | + } elseif ($d('date') && $d('hour')) { |
|
290 | + if ($d('year') && $d('month') && $d('date')) { |
|
291 | + $value .= $r('year').$r('month').$r('date'); |
|
292 | + } elseif (!$d('year') && $d('month') && $d('date')) { |
|
293 | + $value .= '--'.$r('month').$r('date'); |
|
294 | + } elseif (!$d('year') && !$d('month') && $d('date')) { |
|
295 | + $value .= '---'.$r('date'); |
|
296 | + } |
|
297 | + |
|
298 | + $value .= 'T'.$r('hour').$r('minute').$r('second'). |
|
299 | + $r('timezone'); |
|
300 | + } |
|
301 | + |
|
302 | + $writer->writeElement($valueType, $value); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
307 | + * |
|
308 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
309 | + * not yet done, but parameters are not included. |
|
310 | + * |
|
311 | + * @param string $val |
|
312 | + */ |
|
313 | + public function setRawMimeDirValue($val) |
|
314 | + { |
|
315 | + $this->setValue($val); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns a raw mime-dir representation of the value. |
|
320 | + * |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + public function getRawMimeDirValue() |
|
324 | + { |
|
325 | + return implode($this->delimiter, $this->getParts()); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Validates the node for correctness. |
|
330 | + * |
|
331 | + * The following options are supported: |
|
332 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
333 | + * |
|
334 | + * This method returns an array with detected problems. |
|
335 | + * Every element has the following properties: |
|
336 | + * |
|
337 | + * * level - problem level. |
|
338 | + * * message - A human-readable string describing the issue. |
|
339 | + * * node - A reference to the problematic node. |
|
340 | + * |
|
341 | + * The level means: |
|
342 | + * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
343 | + * 2 - An inconsequential issue |
|
344 | + * 3 - A severe issue. |
|
345 | + * |
|
346 | + * @param int $options |
|
347 | + * |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + public function validate($options = 0) |
|
351 | + { |
|
352 | + $messages = parent::validate($options); |
|
353 | + $value = $this->getValue(); |
|
354 | + |
|
355 | + try { |
|
356 | + DateTimeParser::parseVCardDateTime($value); |
|
357 | + } catch (InvalidDataException $e) { |
|
358 | + $messages[] = [ |
|
359 | + 'level' => 3, |
|
360 | + 'message' => 'The supplied value ('.$value.') is not a correct DATE-AND-OR-TIME property', |
|
361 | + 'node' => $this, |
|
362 | + ]; |
|
363 | + } |
|
364 | + |
|
365 | + return $messages; |
|
366 | + } |
|
367 | 367 | } |
@@ -237,12 +237,12 @@ |
||
237 | 237 | $value = ''; |
238 | 238 | |
239 | 239 | // $d = defined |
240 | - $d = function ($part) use ($parts) { |
|
240 | + $d = function($part) use ($parts) { |
|
241 | 241 | return !is_null($parts[$part]); |
242 | 242 | }; |
243 | 243 | |
244 | 244 | // $r = read |
245 | - $r = function ($part) use ($parts) { |
|
245 | + $r = function($part) use ($parts) { |
|
246 | 246 | return $parts[$part]; |
247 | 247 | }; |
248 | 248 |
@@ -13,18 +13,18 @@ |
||
13 | 13 | */ |
14 | 14 | class PhoneNumber extends Property\Text |
15 | 15 | { |
16 | - protected $structuredValues = []; |
|
16 | + protected $structuredValues = []; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Returns the type of value. |
|
20 | - * |
|
21 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
22 | - * 'default' valueType. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getValueType() |
|
27 | - { |
|
28 | - return 'PHONE-NUMBER'; |
|
29 | - } |
|
18 | + /** |
|
19 | + * Returns the type of value. |
|
20 | + * |
|
21 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
22 | + * 'default' valueType. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getValueType() |
|
27 | + { |
|
28 | + return 'PHONE-NUMBER'; |
|
29 | + } |
|
30 | 30 | } |
@@ -15,39 +15,39 @@ |
||
15 | 15 | */ |
16 | 16 | class LanguageTag extends Property |
17 | 17 | { |
18 | - /** |
|
19 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
20 | - * |
|
21 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
22 | - * not yet done, but parameters are not included. |
|
23 | - * |
|
24 | - * @param string $val |
|
25 | - */ |
|
26 | - public function setRawMimeDirValue($val) |
|
27 | - { |
|
28 | - $this->setValue($val); |
|
29 | - } |
|
18 | + /** |
|
19 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
20 | + * |
|
21 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
22 | + * not yet done, but parameters are not included. |
|
23 | + * |
|
24 | + * @param string $val |
|
25 | + */ |
|
26 | + public function setRawMimeDirValue($val) |
|
27 | + { |
|
28 | + $this->setValue($val); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Returns a raw mime-dir representation of the value. |
|
33 | - * |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getRawMimeDirValue() |
|
37 | - { |
|
38 | - return $this->getValue(); |
|
39 | - } |
|
31 | + /** |
|
32 | + * Returns a raw mime-dir representation of the value. |
|
33 | + * |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getRawMimeDirValue() |
|
37 | + { |
|
38 | + return $this->getValue(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the type of value. |
|
43 | - * |
|
44 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
45 | - * 'default' valueType. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getValueType() |
|
50 | - { |
|
51 | - return 'LANGUAGE-TAG'; |
|
52 | - } |
|
41 | + /** |
|
42 | + * Returns the type of value. |
|
43 | + * |
|
44 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
45 | + * 'default' valueType. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getValueType() |
|
50 | + { |
|
51 | + return 'LANGUAGE-TAG'; |
|
52 | + } |
|
53 | 53 | } |