@@ -16,101 +16,101 @@ |
||
16 | 16 | */ |
17 | 17 | class Uri extends Text |
18 | 18 | { |
19 | - /** |
|
20 | - * In case this is a multi-value property. This string will be used as a |
|
21 | - * delimiter. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public $delimiter = ''; |
|
19 | + /** |
|
20 | + * In case this is a multi-value property. This string will be used as a |
|
21 | + * delimiter. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public $delimiter = ''; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Returns the type of value. |
|
29 | - * |
|
30 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
31 | - * 'default' valueType. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function getValueType() |
|
36 | - { |
|
37 | - return 'URI'; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Returns the type of value. |
|
29 | + * |
|
30 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
31 | + * 'default' valueType. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function getValueType() |
|
36 | + { |
|
37 | + return 'URI'; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns an iterable list of children. |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function parameters() |
|
46 | - { |
|
47 | - $parameters = parent::parameters(); |
|
48 | - if (!isset($parameters['VALUE']) && in_array($this->name, ['URL', 'PHOTO'])) { |
|
49 | - // If we are encoding a URI value, and this URI value has no |
|
50 | - // VALUE=URI parameter, we add it anyway. |
|
51 | - // |
|
52 | - // This is not required by any spec, but both Apple iCal and Apple |
|
53 | - // AddressBook (at least in version 10.8) will trip over this if |
|
54 | - // this is not set, and so it improves compatibility. |
|
55 | - // |
|
56 | - // See Issue #227 and #235 |
|
57 | - $parameters['VALUE'] = new Parameter($this->root, 'VALUE', 'URI'); |
|
58 | - } |
|
40 | + /** |
|
41 | + * Returns an iterable list of children. |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function parameters() |
|
46 | + { |
|
47 | + $parameters = parent::parameters(); |
|
48 | + if (!isset($parameters['VALUE']) && in_array($this->name, ['URL', 'PHOTO'])) { |
|
49 | + // If we are encoding a URI value, and this URI value has no |
|
50 | + // VALUE=URI parameter, we add it anyway. |
|
51 | + // |
|
52 | + // This is not required by any spec, but both Apple iCal and Apple |
|
53 | + // AddressBook (at least in version 10.8) will trip over this if |
|
54 | + // this is not set, and so it improves compatibility. |
|
55 | + // |
|
56 | + // See Issue #227 and #235 |
|
57 | + $parameters['VALUE'] = new Parameter($this->root, 'VALUE', 'URI'); |
|
58 | + } |
|
59 | 59 | |
60 | - return $parameters; |
|
61 | - } |
|
60 | + return $parameters; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
65 | - * |
|
66 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
67 | - * not yet done, but parameters are not included. |
|
68 | - * |
|
69 | - * @param string $val |
|
70 | - */ |
|
71 | - public function setRawMimeDirValue($val) |
|
72 | - { |
|
73 | - // Normally we don't need to do any type of unescaping for these |
|
74 | - // properties, however.. we've noticed that Google Contacts |
|
75 | - // specifically escapes the colon (:) with a backslash. While I have |
|
76 | - // no clue why they thought that was a good idea, I'm unescaping it |
|
77 | - // anyway. |
|
78 | - // |
|
79 | - // Good thing backslashes are not allowed in urls. Makes it easy to |
|
80 | - // assume that a backslash is always intended as an escape character. |
|
81 | - if ('URL' === $this->name) { |
|
82 | - $regex = '# (?: (\\\\ (?: \\\\ | : ) ) ) #x'; |
|
83 | - $matches = preg_split($regex, $val, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
84 | - $newVal = ''; |
|
85 | - foreach ($matches as $match) { |
|
86 | - switch ($match) { |
|
87 | - case '\:': |
|
88 | - $newVal .= ':'; |
|
89 | - break; |
|
90 | - default: |
|
91 | - $newVal .= $match; |
|
92 | - break; |
|
93 | - } |
|
94 | - } |
|
95 | - $this->value = $newVal; |
|
96 | - } else { |
|
97 | - $this->value = strtr($val, ['\,' => ',']); |
|
98 | - } |
|
99 | - } |
|
63 | + /** |
|
64 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
65 | + * |
|
66 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
67 | + * not yet done, but parameters are not included. |
|
68 | + * |
|
69 | + * @param string $val |
|
70 | + */ |
|
71 | + public function setRawMimeDirValue($val) |
|
72 | + { |
|
73 | + // Normally we don't need to do any type of unescaping for these |
|
74 | + // properties, however.. we've noticed that Google Contacts |
|
75 | + // specifically escapes the colon (:) with a backslash. While I have |
|
76 | + // no clue why they thought that was a good idea, I'm unescaping it |
|
77 | + // anyway. |
|
78 | + // |
|
79 | + // Good thing backslashes are not allowed in urls. Makes it easy to |
|
80 | + // assume that a backslash is always intended as an escape character. |
|
81 | + if ('URL' === $this->name) { |
|
82 | + $regex = '# (?: (\\\\ (?: \\\\ | : ) ) ) #x'; |
|
83 | + $matches = preg_split($regex, $val, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
84 | + $newVal = ''; |
|
85 | + foreach ($matches as $match) { |
|
86 | + switch ($match) { |
|
87 | + case '\:': |
|
88 | + $newVal .= ':'; |
|
89 | + break; |
|
90 | + default: |
|
91 | + $newVal .= $match; |
|
92 | + break; |
|
93 | + } |
|
94 | + } |
|
95 | + $this->value = $newVal; |
|
96 | + } else { |
|
97 | + $this->value = strtr($val, ['\,' => ',']); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Returns a raw mime-dir representation of the value. |
|
103 | - * |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function getRawMimeDirValue() |
|
107 | - { |
|
108 | - if (is_array($this->value)) { |
|
109 | - $value = $this->value[0]; |
|
110 | - } else { |
|
111 | - $value = $this->value; |
|
112 | - } |
|
101 | + /** |
|
102 | + * Returns a raw mime-dir representation of the value. |
|
103 | + * |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function getRawMimeDirValue() |
|
107 | + { |
|
108 | + if (is_array($this->value)) { |
|
109 | + $value = $this->value[0]; |
|
110 | + } else { |
|
111 | + $value = $this->value; |
|
112 | + } |
|
113 | 113 | |
114 | - return strtr($value, [',' => '\,']); |
|
115 | - } |
|
114 | + return strtr($value, [',' => '\,']); |
|
115 | + } |
|
116 | 116 | } |
@@ -13,58 +13,58 @@ |
||
13 | 13 | */ |
14 | 14 | class UtcOffset extends Text |
15 | 15 | { |
16 | - /** |
|
17 | - * In case this is a multi-value property. This string will be used as a |
|
18 | - * delimiter. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $delimiter = ''; |
|
16 | + /** |
|
17 | + * In case this is a multi-value property. This string will be used as a |
|
18 | + * delimiter. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $delimiter = ''; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Returns the type of value. |
|
26 | - * |
|
27 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
28 | - * 'default' valueType. |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getValueType() |
|
33 | - { |
|
34 | - return 'UTC-OFFSET'; |
|
35 | - } |
|
24 | + /** |
|
25 | + * Returns the type of value. |
|
26 | + * |
|
27 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
28 | + * 'default' valueType. |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getValueType() |
|
33 | + { |
|
34 | + return 'UTC-OFFSET'; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Sets the JSON value, as it would appear in a jCard or jCal object. |
|
39 | - * |
|
40 | - * The value must always be an array. |
|
41 | - */ |
|
42 | - public function setJsonValue(array $value) |
|
43 | - { |
|
44 | - $value = array_map( |
|
45 | - function ($value) { |
|
46 | - return str_replace(':', '', $value); |
|
47 | - }, |
|
48 | - $value |
|
49 | - ); |
|
50 | - parent::setJsonValue($value); |
|
51 | - } |
|
37 | + /** |
|
38 | + * Sets the JSON value, as it would appear in a jCard or jCal object. |
|
39 | + * |
|
40 | + * The value must always be an array. |
|
41 | + */ |
|
42 | + public function setJsonValue(array $value) |
|
43 | + { |
|
44 | + $value = array_map( |
|
45 | + function ($value) { |
|
46 | + return str_replace(':', '', $value); |
|
47 | + }, |
|
48 | + $value |
|
49 | + ); |
|
50 | + parent::setJsonValue($value); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the value, in the format it should be encoded for JSON. |
|
55 | - * |
|
56 | - * This method must always return an array. |
|
57 | - * |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function getJsonValue() |
|
61 | - { |
|
62 | - return array_map( |
|
63 | - function ($value) { |
|
64 | - return substr($value, 0, -2).':'. |
|
65 | - substr($value, -2); |
|
66 | - }, |
|
67 | - parent::getJsonValue() |
|
68 | - ); |
|
69 | - } |
|
53 | + /** |
|
54 | + * Returns the value, in the format it should be encoded for JSON. |
|
55 | + * |
|
56 | + * This method must always return an array. |
|
57 | + * |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function getJsonValue() |
|
61 | + { |
|
62 | + return array_map( |
|
63 | + function ($value) { |
|
64 | + return substr($value, 0, -2).':'. |
|
65 | + substr($value, -2); |
|
66 | + }, |
|
67 | + parent::getJsonValue() |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | } |
@@ -19,117 +19,117 @@ |
||
19 | 19 | */ |
20 | 20 | class Period extends Property |
21 | 21 | { |
22 | - /** |
|
23 | - * In case this is a multi-value property. This string will be used as a |
|
24 | - * delimiter. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $delimiter = ','; |
|
22 | + /** |
|
23 | + * In case this is a multi-value property. This string will be used as a |
|
24 | + * delimiter. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $delimiter = ','; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
32 | - * |
|
33 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
34 | - * not yet done, but parameters are not included. |
|
35 | - * |
|
36 | - * @param string $val |
|
37 | - */ |
|
38 | - public function setRawMimeDirValue($val) |
|
39 | - { |
|
40 | - $this->setValue(explode($this->delimiter, $val)); |
|
41 | - } |
|
30 | + /** |
|
31 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
32 | + * |
|
33 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
34 | + * not yet done, but parameters are not included. |
|
35 | + * |
|
36 | + * @param string $val |
|
37 | + */ |
|
38 | + public function setRawMimeDirValue($val) |
|
39 | + { |
|
40 | + $this->setValue(explode($this->delimiter, $val)); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns a raw mime-dir representation of the value. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getRawMimeDirValue() |
|
49 | - { |
|
50 | - return implode($this->delimiter, $this->getParts()); |
|
51 | - } |
|
43 | + /** |
|
44 | + * Returns a raw mime-dir representation of the value. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getRawMimeDirValue() |
|
49 | + { |
|
50 | + return implode($this->delimiter, $this->getParts()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the type of value. |
|
55 | - * |
|
56 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
57 | - * 'default' valueType. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getValueType() |
|
62 | - { |
|
63 | - return 'PERIOD'; |
|
64 | - } |
|
53 | + /** |
|
54 | + * Returns the type of value. |
|
55 | + * |
|
56 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
57 | + * 'default' valueType. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getValueType() |
|
62 | + { |
|
63 | + return 'PERIOD'; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Sets the json value, as it would appear in a jCard or jCal object. |
|
68 | - * |
|
69 | - * The value must always be an array. |
|
70 | - */ |
|
71 | - public function setJsonValue(array $value) |
|
72 | - { |
|
73 | - $value = array_map( |
|
74 | - function ($item) { |
|
75 | - return strtr(implode('/', $item), [':' => '', '-' => '']); |
|
76 | - }, |
|
77 | - $value |
|
78 | - ); |
|
79 | - parent::setJsonValue($value); |
|
80 | - } |
|
66 | + /** |
|
67 | + * Sets the json value, as it would appear in a jCard or jCal object. |
|
68 | + * |
|
69 | + * The value must always be an array. |
|
70 | + */ |
|
71 | + public function setJsonValue(array $value) |
|
72 | + { |
|
73 | + $value = array_map( |
|
74 | + function ($item) { |
|
75 | + return strtr(implode('/', $item), [':' => '', '-' => '']); |
|
76 | + }, |
|
77 | + $value |
|
78 | + ); |
|
79 | + parent::setJsonValue($value); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns the value, in the format it should be encoded for json. |
|
84 | - * |
|
85 | - * This method must always return an array. |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function getJsonValue() |
|
90 | - { |
|
91 | - $return = []; |
|
92 | - foreach ($this->getParts() as $item) { |
|
93 | - list($start, $end) = explode('/', $item, 2); |
|
82 | + /** |
|
83 | + * Returns the value, in the format it should be encoded for json. |
|
84 | + * |
|
85 | + * This method must always return an array. |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function getJsonValue() |
|
90 | + { |
|
91 | + $return = []; |
|
92 | + foreach ($this->getParts() as $item) { |
|
93 | + list($start, $end) = explode('/', $item, 2); |
|
94 | 94 | |
95 | - $start = DateTimeParser::parseDateTime($start); |
|
95 | + $start = DateTimeParser::parseDateTime($start); |
|
96 | 96 | |
97 | - // This is a duration value. |
|
98 | - if ('P' === $end[0]) { |
|
99 | - $return[] = [ |
|
100 | - $start->format('Y-m-d\\TH:i:s'), |
|
101 | - $end, |
|
102 | - ]; |
|
103 | - } else { |
|
104 | - $end = DateTimeParser::parseDateTime($end); |
|
105 | - $return[] = [ |
|
106 | - $start->format('Y-m-d\\TH:i:s'), |
|
107 | - $end->format('Y-m-d\\TH:i:s'), |
|
108 | - ]; |
|
109 | - } |
|
110 | - } |
|
97 | + // This is a duration value. |
|
98 | + if ('P' === $end[0]) { |
|
99 | + $return[] = [ |
|
100 | + $start->format('Y-m-d\\TH:i:s'), |
|
101 | + $end, |
|
102 | + ]; |
|
103 | + } else { |
|
104 | + $end = DateTimeParser::parseDateTime($end); |
|
105 | + $return[] = [ |
|
106 | + $start->format('Y-m-d\\TH:i:s'), |
|
107 | + $end->format('Y-m-d\\TH:i:s'), |
|
108 | + ]; |
|
109 | + } |
|
110 | + } |
|
111 | 111 | |
112 | - return $return; |
|
113 | - } |
|
112 | + return $return; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * This method serializes only the value of a property. This is used to |
|
117 | - * create xCard or xCal documents. |
|
118 | - * |
|
119 | - * @param Xml\Writer $writer XML writer |
|
120 | - */ |
|
121 | - protected function xmlSerializeValue(Xml\Writer $writer) |
|
122 | - { |
|
123 | - $writer->startElement(strtolower($this->getValueType())); |
|
124 | - $value = $this->getJsonValue(); |
|
125 | - $writer->writeElement('start', $value[0][0]); |
|
115 | + /** |
|
116 | + * This method serializes only the value of a property. This is used to |
|
117 | + * create xCard or xCal documents. |
|
118 | + * |
|
119 | + * @param Xml\Writer $writer XML writer |
|
120 | + */ |
|
121 | + protected function xmlSerializeValue(Xml\Writer $writer) |
|
122 | + { |
|
123 | + $writer->startElement(strtolower($this->getValueType())); |
|
124 | + $value = $this->getJsonValue(); |
|
125 | + $writer->writeElement('start', $value[0][0]); |
|
126 | 126 | |
127 | - if ('P' === $value[0][1][0]) { |
|
128 | - $writer->writeElement('duration', $value[0][1]); |
|
129 | - } else { |
|
130 | - $writer->writeElement('end', $value[0][1]); |
|
131 | - } |
|
127 | + if ('P' === $value[0][1][0]) { |
|
128 | + $writer->writeElement('duration', $value[0][1]); |
|
129 | + } else { |
|
130 | + $writer->writeElement('end', $value[0][1]); |
|
131 | + } |
|
132 | 132 | |
133 | - $writer->endElement(); |
|
134 | - } |
|
133 | + $writer->endElement(); |
|
134 | + } |
|
135 | 135 | } |
@@ -18,62 +18,62 @@ |
||
18 | 18 | */ |
19 | 19 | class Duration extends Property |
20 | 20 | { |
21 | - /** |
|
22 | - * In case this is a multi-value property. This string will be used as a |
|
23 | - * delimiter. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $delimiter = ','; |
|
21 | + /** |
|
22 | + * In case this is a multi-value property. This string will be used as a |
|
23 | + * delimiter. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $delimiter = ','; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
31 | - * |
|
32 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
33 | - * not yet done, but parameters are not included. |
|
34 | - * |
|
35 | - * @param string $val |
|
36 | - */ |
|
37 | - public function setRawMimeDirValue($val) |
|
38 | - { |
|
39 | - $this->setValue(explode($this->delimiter, $val)); |
|
40 | - } |
|
29 | + /** |
|
30 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
31 | + * |
|
32 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
33 | + * not yet done, but parameters are not included. |
|
34 | + * |
|
35 | + * @param string $val |
|
36 | + */ |
|
37 | + public function setRawMimeDirValue($val) |
|
38 | + { |
|
39 | + $this->setValue(explode($this->delimiter, $val)); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns a raw mime-dir representation of the value. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getRawMimeDirValue() |
|
48 | - { |
|
49 | - return implode($this->delimiter, $this->getParts()); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Returns a raw mime-dir representation of the value. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getRawMimeDirValue() |
|
48 | + { |
|
49 | + return implode($this->delimiter, $this->getParts()); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns the type of value. |
|
54 | - * |
|
55 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
56 | - * 'default' valueType. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getValueType() |
|
61 | - { |
|
62 | - return 'DURATION'; |
|
63 | - } |
|
52 | + /** |
|
53 | + * Returns the type of value. |
|
54 | + * |
|
55 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
56 | + * 'default' valueType. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getValueType() |
|
61 | + { |
|
62 | + return 'DURATION'; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns a DateInterval representation of the Duration property. |
|
67 | - * |
|
68 | - * If the property has more than one value, only the first is returned. |
|
69 | - * |
|
70 | - * @return \DateInterval |
|
71 | - */ |
|
72 | - public function getDateInterval() |
|
73 | - { |
|
74 | - $parts = $this->getParts(); |
|
75 | - $value = $parts[0]; |
|
65 | + /** |
|
66 | + * Returns a DateInterval representation of the Duration property. |
|
67 | + * |
|
68 | + * If the property has more than one value, only the first is returned. |
|
69 | + * |
|
70 | + * @return \DateInterval |
|
71 | + */ |
|
72 | + public function getDateInterval() |
|
73 | + { |
|
74 | + $parts = $this->getParts(); |
|
75 | + $value = $parts[0]; |
|
76 | 76 | |
77 | - return DateTimeParser::parseDuration($value); |
|
78 | - } |
|
77 | + return DateTimeParser::parseDuration($value); |
|
78 | + } |
|
79 | 79 | } |
@@ -24,313 +24,313 @@ |
||
24 | 24 | */ |
25 | 25 | class Recur extends Property |
26 | 26 | { |
27 | - /** |
|
28 | - * Updates the current value. |
|
29 | - * |
|
30 | - * This may be either a single, or multiple strings in an array. |
|
31 | - * |
|
32 | - * @param string|array $value |
|
33 | - */ |
|
34 | - public function setValue($value) |
|
35 | - { |
|
36 | - // If we're getting the data from json, we'll be receiving an object |
|
37 | - if ($value instanceof \StdClass) { |
|
38 | - $value = (array) $value; |
|
39 | - } |
|
27 | + /** |
|
28 | + * Updates the current value. |
|
29 | + * |
|
30 | + * This may be either a single, or multiple strings in an array. |
|
31 | + * |
|
32 | + * @param string|array $value |
|
33 | + */ |
|
34 | + public function setValue($value) |
|
35 | + { |
|
36 | + // If we're getting the data from json, we'll be receiving an object |
|
37 | + if ($value instanceof \StdClass) { |
|
38 | + $value = (array) $value; |
|
39 | + } |
|
40 | 40 | |
41 | - if (is_array($value)) { |
|
42 | - $newVal = []; |
|
43 | - foreach ($value as $k => $v) { |
|
44 | - if (is_string($v)) { |
|
45 | - $v = strtoupper($v); |
|
41 | + if (is_array($value)) { |
|
42 | + $newVal = []; |
|
43 | + foreach ($value as $k => $v) { |
|
44 | + if (is_string($v)) { |
|
45 | + $v = strtoupper($v); |
|
46 | 46 | |
47 | - // The value had multiple sub-values |
|
48 | - if (false !== strpos($v, ',')) { |
|
49 | - $v = explode(',', $v); |
|
50 | - } |
|
51 | - if (0 === strcmp($k, 'until')) { |
|
52 | - $v = strtr($v, [':' => '', '-' => '']); |
|
53 | - } |
|
54 | - } elseif (is_array($v)) { |
|
55 | - $v = array_map('strtoupper', $v); |
|
56 | - } |
|
47 | + // The value had multiple sub-values |
|
48 | + if (false !== strpos($v, ',')) { |
|
49 | + $v = explode(',', $v); |
|
50 | + } |
|
51 | + if (0 === strcmp($k, 'until')) { |
|
52 | + $v = strtr($v, [':' => '', '-' => '']); |
|
53 | + } |
|
54 | + } elseif (is_array($v)) { |
|
55 | + $v = array_map('strtoupper', $v); |
|
56 | + } |
|
57 | 57 | |
58 | - $newVal[strtoupper($k)] = $v; |
|
59 | - } |
|
60 | - $this->value = $newVal; |
|
61 | - } elseif (is_string($value)) { |
|
62 | - $this->value = self::stringToArray($value); |
|
63 | - } else { |
|
64 | - throw new \InvalidArgumentException('You must either pass a string, or a key=>value array'); |
|
65 | - } |
|
66 | - } |
|
58 | + $newVal[strtoupper($k)] = $v; |
|
59 | + } |
|
60 | + $this->value = $newVal; |
|
61 | + } elseif (is_string($value)) { |
|
62 | + $this->value = self::stringToArray($value); |
|
63 | + } else { |
|
64 | + throw new \InvalidArgumentException('You must either pass a string, or a key=>value array'); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Returns the current value. |
|
70 | - * |
|
71 | - * This method will always return a singular value. If this was a |
|
72 | - * multi-value object, some decision will be made first on how to represent |
|
73 | - * it as a string. |
|
74 | - * |
|
75 | - * To get the correct multi-value version, use getParts. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getValue() |
|
80 | - { |
|
81 | - $out = []; |
|
82 | - foreach ($this->value as $key => $value) { |
|
83 | - $out[] = $key.'='.(is_array($value) ? implode(',', $value) : $value); |
|
84 | - } |
|
68 | + /** |
|
69 | + * Returns the current value. |
|
70 | + * |
|
71 | + * This method will always return a singular value. If this was a |
|
72 | + * multi-value object, some decision will be made first on how to represent |
|
73 | + * it as a string. |
|
74 | + * |
|
75 | + * To get the correct multi-value version, use getParts. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getValue() |
|
80 | + { |
|
81 | + $out = []; |
|
82 | + foreach ($this->value as $key => $value) { |
|
83 | + $out[] = $key.'='.(is_array($value) ? implode(',', $value) : $value); |
|
84 | + } |
|
85 | 85 | |
86 | - return strtoupper(implode(';', $out)); |
|
87 | - } |
|
86 | + return strtoupper(implode(';', $out)); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Sets a multi-valued property. |
|
91 | - */ |
|
92 | - public function setParts(array $parts) |
|
93 | - { |
|
94 | - $this->setValue($parts); |
|
95 | - } |
|
89 | + /** |
|
90 | + * Sets a multi-valued property. |
|
91 | + */ |
|
92 | + public function setParts(array $parts) |
|
93 | + { |
|
94 | + $this->setValue($parts); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Returns a multi-valued property. |
|
99 | - * |
|
100 | - * This method always returns an array, if there was only a single value, |
|
101 | - * it will still be wrapped in an array. |
|
102 | - * |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getParts() |
|
106 | - { |
|
107 | - return $this->value; |
|
108 | - } |
|
97 | + /** |
|
98 | + * Returns a multi-valued property. |
|
99 | + * |
|
100 | + * This method always returns an array, if there was only a single value, |
|
101 | + * it will still be wrapped in an array. |
|
102 | + * |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getParts() |
|
106 | + { |
|
107 | + return $this->value; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
112 | - * |
|
113 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
114 | - * not yet done, but parameters are not included. |
|
115 | - * |
|
116 | - * @param string $val |
|
117 | - */ |
|
118 | - public function setRawMimeDirValue($val) |
|
119 | - { |
|
120 | - $this->setValue($val); |
|
121 | - } |
|
110 | + /** |
|
111 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
112 | + * |
|
113 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
114 | + * not yet done, but parameters are not included. |
|
115 | + * |
|
116 | + * @param string $val |
|
117 | + */ |
|
118 | + public function setRawMimeDirValue($val) |
|
119 | + { |
|
120 | + $this->setValue($val); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Returns a raw mime-dir representation of the value. |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function getRawMimeDirValue() |
|
129 | - { |
|
130 | - return $this->getValue(); |
|
131 | - } |
|
123 | + /** |
|
124 | + * Returns a raw mime-dir representation of the value. |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function getRawMimeDirValue() |
|
129 | + { |
|
130 | + return $this->getValue(); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Returns the type of value. |
|
135 | - * |
|
136 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
137 | - * 'default' valueType. |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getValueType() |
|
142 | - { |
|
143 | - return 'RECUR'; |
|
144 | - } |
|
133 | + /** |
|
134 | + * Returns the type of value. |
|
135 | + * |
|
136 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
137 | + * 'default' valueType. |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getValueType() |
|
142 | + { |
|
143 | + return 'RECUR'; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Returns the value, in the format it should be encoded for json. |
|
148 | - * |
|
149 | - * This method must always return an array. |
|
150 | - * |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function getJsonValue() |
|
154 | - { |
|
155 | - $values = []; |
|
156 | - foreach ($this->getParts() as $k => $v) { |
|
157 | - if (0 === strcmp($k, 'UNTIL')) { |
|
158 | - $date = new DateTime($this->root, null, $v); |
|
159 | - $values[strtolower($k)] = $date->getJsonValue()[0]; |
|
160 | - } elseif (0 === strcmp($k, 'COUNT')) { |
|
161 | - $values[strtolower($k)] = intval($v); |
|
162 | - } else { |
|
163 | - $values[strtolower($k)] = $v; |
|
164 | - } |
|
165 | - } |
|
146 | + /** |
|
147 | + * Returns the value, in the format it should be encoded for json. |
|
148 | + * |
|
149 | + * This method must always return an array. |
|
150 | + * |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function getJsonValue() |
|
154 | + { |
|
155 | + $values = []; |
|
156 | + foreach ($this->getParts() as $k => $v) { |
|
157 | + if (0 === strcmp($k, 'UNTIL')) { |
|
158 | + $date = new DateTime($this->root, null, $v); |
|
159 | + $values[strtolower($k)] = $date->getJsonValue()[0]; |
|
160 | + } elseif (0 === strcmp($k, 'COUNT')) { |
|
161 | + $values[strtolower($k)] = intval($v); |
|
162 | + } else { |
|
163 | + $values[strtolower($k)] = $v; |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - return [$values]; |
|
168 | - } |
|
167 | + return [$values]; |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * This method serializes only the value of a property. This is used to |
|
172 | - * create xCard or xCal documents. |
|
173 | - * |
|
174 | - * @param Xml\Writer $writer XML writer |
|
175 | - */ |
|
176 | - protected function xmlSerializeValue(Xml\Writer $writer) |
|
177 | - { |
|
178 | - $valueType = strtolower($this->getValueType()); |
|
170 | + /** |
|
171 | + * This method serializes only the value of a property. This is used to |
|
172 | + * create xCard or xCal documents. |
|
173 | + * |
|
174 | + * @param Xml\Writer $writer XML writer |
|
175 | + */ |
|
176 | + protected function xmlSerializeValue(Xml\Writer $writer) |
|
177 | + { |
|
178 | + $valueType = strtolower($this->getValueType()); |
|
179 | 179 | |
180 | - foreach ($this->getJsonValue() as $value) { |
|
181 | - $writer->writeElement($valueType, $value); |
|
182 | - } |
|
183 | - } |
|
180 | + foreach ($this->getJsonValue() as $value) { |
|
181 | + $writer->writeElement($valueType, $value); |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Parses an RRULE value string, and turns it into a struct-ish array. |
|
187 | - * |
|
188 | - * @param string $value |
|
189 | - * |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public static function stringToArray($value) |
|
193 | - { |
|
194 | - $value = strtoupper($value); |
|
195 | - $newValue = []; |
|
196 | - foreach (explode(';', $value) as $part) { |
|
197 | - // Skipping empty parts. |
|
198 | - if (empty($part)) { |
|
199 | - continue; |
|
200 | - } |
|
201 | - list($partName, $partValue) = explode('=', $part); |
|
185 | + /** |
|
186 | + * Parses an RRULE value string, and turns it into a struct-ish array. |
|
187 | + * |
|
188 | + * @param string $value |
|
189 | + * |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public static function stringToArray($value) |
|
193 | + { |
|
194 | + $value = strtoupper($value); |
|
195 | + $newValue = []; |
|
196 | + foreach (explode(';', $value) as $part) { |
|
197 | + // Skipping empty parts. |
|
198 | + if (empty($part)) { |
|
199 | + continue; |
|
200 | + } |
|
201 | + list($partName, $partValue) = explode('=', $part); |
|
202 | 202 | |
203 | - // The value itself had multiple values.. |
|
204 | - if (false !== strpos($partValue, ',')) { |
|
205 | - $partValue = explode(',', $partValue); |
|
206 | - } |
|
207 | - $newValue[$partName] = $partValue; |
|
208 | - } |
|
203 | + // The value itself had multiple values.. |
|
204 | + if (false !== strpos($partValue, ',')) { |
|
205 | + $partValue = explode(',', $partValue); |
|
206 | + } |
|
207 | + $newValue[$partName] = $partValue; |
|
208 | + } |
|
209 | 209 | |
210 | - return $newValue; |
|
211 | - } |
|
210 | + return $newValue; |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Validates the node for correctness. |
|
215 | - * |
|
216 | - * The following options are supported: |
|
217 | - * Node::REPAIR - May attempt to automatically repair the problem. |
|
218 | - * |
|
219 | - * This method returns an array with detected problems. |
|
220 | - * Every element has the following properties: |
|
221 | - * |
|
222 | - * * level - problem level. |
|
223 | - * * message - A human-readable string describing the issue. |
|
224 | - * * node - A reference to the problematic node. |
|
225 | - * |
|
226 | - * The level means: |
|
227 | - * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
228 | - * 2 - An inconsequential issue |
|
229 | - * 3 - A severe issue. |
|
230 | - * |
|
231 | - * @param int $options |
|
232 | - * |
|
233 | - * @return array |
|
234 | - */ |
|
235 | - public function validate($options = 0) |
|
236 | - { |
|
237 | - $repair = ($options & self::REPAIR); |
|
213 | + /** |
|
214 | + * Validates the node for correctness. |
|
215 | + * |
|
216 | + * The following options are supported: |
|
217 | + * Node::REPAIR - May attempt to automatically repair the problem. |
|
218 | + * |
|
219 | + * This method returns an array with detected problems. |
|
220 | + * Every element has the following properties: |
|
221 | + * |
|
222 | + * * level - problem level. |
|
223 | + * * message - A human-readable string describing the issue. |
|
224 | + * * node - A reference to the problematic node. |
|
225 | + * |
|
226 | + * The level means: |
|
227 | + * 1 - The issue was repaired (only happens if REPAIR was turned on) |
|
228 | + * 2 - An inconsequential issue |
|
229 | + * 3 - A severe issue. |
|
230 | + * |
|
231 | + * @param int $options |
|
232 | + * |
|
233 | + * @return array |
|
234 | + */ |
|
235 | + public function validate($options = 0) |
|
236 | + { |
|
237 | + $repair = ($options & self::REPAIR); |
|
238 | 238 | |
239 | - $warnings = parent::validate($options); |
|
240 | - $values = $this->getParts(); |
|
239 | + $warnings = parent::validate($options); |
|
240 | + $values = $this->getParts(); |
|
241 | 241 | |
242 | - foreach ($values as $key => $value) { |
|
243 | - if ('' === $value) { |
|
244 | - $warnings[] = [ |
|
245 | - 'level' => $repair ? 1 : 3, |
|
246 | - 'message' => 'Invalid value for '.$key.' in '.$this->name, |
|
247 | - 'node' => $this, |
|
248 | - ]; |
|
249 | - if ($repair) { |
|
250 | - unset($values[$key]); |
|
251 | - } |
|
252 | - } elseif ('BYMONTH' == $key) { |
|
253 | - $byMonth = (array) $value; |
|
254 | - foreach ($byMonth as $i => $v) { |
|
255 | - if (!is_numeric($v) || (int) $v < 1 || (int) $v > 12) { |
|
256 | - $warnings[] = [ |
|
257 | - 'level' => $repair ? 1 : 3, |
|
258 | - 'message' => 'BYMONTH in RRULE must have value(s) between 1 and 12!', |
|
259 | - 'node' => $this, |
|
260 | - ]; |
|
261 | - if ($repair) { |
|
262 | - if (is_array($value)) { |
|
263 | - unset($values[$key][$i]); |
|
264 | - } else { |
|
265 | - unset($values[$key]); |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
270 | - // if there is no valid entry left, remove the whole value |
|
271 | - if (is_array($value) && empty($values[$key])) { |
|
272 | - unset($values[$key]); |
|
273 | - } |
|
274 | - } elseif ('BYWEEKNO' == $key) { |
|
275 | - $byWeekNo = (array) $value; |
|
276 | - foreach ($byWeekNo as $i => $v) { |
|
277 | - if (!is_numeric($v) || (int) $v < -53 || 0 == (int) $v || (int) $v > 53) { |
|
278 | - $warnings[] = [ |
|
279 | - 'level' => $repair ? 1 : 3, |
|
280 | - 'message' => 'BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', |
|
281 | - 'node' => $this, |
|
282 | - ]; |
|
283 | - if ($repair) { |
|
284 | - if (is_array($value)) { |
|
285 | - unset($values[$key][$i]); |
|
286 | - } else { |
|
287 | - unset($values[$key]); |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - // if there is no valid entry left, remove the whole value |
|
293 | - if (is_array($value) && empty($values[$key])) { |
|
294 | - unset($values[$key]); |
|
295 | - } |
|
296 | - } elseif ('BYYEARDAY' == $key) { |
|
297 | - $byYearDay = (array) $value; |
|
298 | - foreach ($byYearDay as $i => $v) { |
|
299 | - if (!is_numeric($v) || (int) $v < -366 || 0 == (int) $v || (int) $v > 366) { |
|
300 | - $warnings[] = [ |
|
301 | - 'level' => $repair ? 1 : 3, |
|
302 | - 'message' => 'BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', |
|
303 | - 'node' => $this, |
|
304 | - ]; |
|
305 | - if ($repair) { |
|
306 | - if (is_array($value)) { |
|
307 | - unset($values[$key][$i]); |
|
308 | - } else { |
|
309 | - unset($values[$key]); |
|
310 | - } |
|
311 | - } |
|
312 | - } |
|
313 | - } |
|
314 | - // if there is no valid entry left, remove the whole value |
|
315 | - if (is_array($value) && empty($values[$key])) { |
|
316 | - unset($values[$key]); |
|
317 | - } |
|
318 | - } |
|
319 | - } |
|
320 | - if (!isset($values['FREQ'])) { |
|
321 | - $warnings[] = [ |
|
322 | - 'level' => $repair ? 1 : 3, |
|
323 | - 'message' => 'FREQ is required in '.$this->name, |
|
324 | - 'node' => $this, |
|
325 | - ]; |
|
326 | - if ($repair) { |
|
327 | - $this->parent->remove($this); |
|
328 | - } |
|
329 | - } |
|
330 | - if ($repair) { |
|
331 | - $this->setValue($values); |
|
332 | - } |
|
242 | + foreach ($values as $key => $value) { |
|
243 | + if ('' === $value) { |
|
244 | + $warnings[] = [ |
|
245 | + 'level' => $repair ? 1 : 3, |
|
246 | + 'message' => 'Invalid value for '.$key.' in '.$this->name, |
|
247 | + 'node' => $this, |
|
248 | + ]; |
|
249 | + if ($repair) { |
|
250 | + unset($values[$key]); |
|
251 | + } |
|
252 | + } elseif ('BYMONTH' == $key) { |
|
253 | + $byMonth = (array) $value; |
|
254 | + foreach ($byMonth as $i => $v) { |
|
255 | + if (!is_numeric($v) || (int) $v < 1 || (int) $v > 12) { |
|
256 | + $warnings[] = [ |
|
257 | + 'level' => $repair ? 1 : 3, |
|
258 | + 'message' => 'BYMONTH in RRULE must have value(s) between 1 and 12!', |
|
259 | + 'node' => $this, |
|
260 | + ]; |
|
261 | + if ($repair) { |
|
262 | + if (is_array($value)) { |
|
263 | + unset($values[$key][$i]); |
|
264 | + } else { |
|
265 | + unset($values[$key]); |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | + // if there is no valid entry left, remove the whole value |
|
271 | + if (is_array($value) && empty($values[$key])) { |
|
272 | + unset($values[$key]); |
|
273 | + } |
|
274 | + } elseif ('BYWEEKNO' == $key) { |
|
275 | + $byWeekNo = (array) $value; |
|
276 | + foreach ($byWeekNo as $i => $v) { |
|
277 | + if (!is_numeric($v) || (int) $v < -53 || 0 == (int) $v || (int) $v > 53) { |
|
278 | + $warnings[] = [ |
|
279 | + 'level' => $repair ? 1 : 3, |
|
280 | + 'message' => 'BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', |
|
281 | + 'node' => $this, |
|
282 | + ]; |
|
283 | + if ($repair) { |
|
284 | + if (is_array($value)) { |
|
285 | + unset($values[$key][$i]); |
|
286 | + } else { |
|
287 | + unset($values[$key]); |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + // if there is no valid entry left, remove the whole value |
|
293 | + if (is_array($value) && empty($values[$key])) { |
|
294 | + unset($values[$key]); |
|
295 | + } |
|
296 | + } elseif ('BYYEARDAY' == $key) { |
|
297 | + $byYearDay = (array) $value; |
|
298 | + foreach ($byYearDay as $i => $v) { |
|
299 | + if (!is_numeric($v) || (int) $v < -366 || 0 == (int) $v || (int) $v > 366) { |
|
300 | + $warnings[] = [ |
|
301 | + 'level' => $repair ? 1 : 3, |
|
302 | + 'message' => 'BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', |
|
303 | + 'node' => $this, |
|
304 | + ]; |
|
305 | + if ($repair) { |
|
306 | + if (is_array($value)) { |
|
307 | + unset($values[$key][$i]); |
|
308 | + } else { |
|
309 | + unset($values[$key]); |
|
310 | + } |
|
311 | + } |
|
312 | + } |
|
313 | + } |
|
314 | + // if there is no valid entry left, remove the whole value |
|
315 | + if (is_array($value) && empty($values[$key])) { |
|
316 | + unset($values[$key]); |
|
317 | + } |
|
318 | + } |
|
319 | + } |
|
320 | + if (!isset($values['FREQ'])) { |
|
321 | + $warnings[] = [ |
|
322 | + 'level' => $repair ? 1 : 3, |
|
323 | + 'message' => 'FREQ is required in '.$this->name, |
|
324 | + 'node' => $this, |
|
325 | + ]; |
|
326 | + if ($repair) { |
|
327 | + $this->parent->remove($this); |
|
328 | + } |
|
329 | + } |
|
330 | + if ($repair) { |
|
331 | + $this->setValue($values); |
|
332 | + } |
|
333 | 333 | |
334 | - return $warnings; |
|
335 | - } |
|
334 | + return $warnings; |
|
335 | + } |
|
336 | 336 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |