@@ -14,28 +14,28 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Unknown extends Text |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Returns the value, in the format it should be encoded for json. |
|
| 19 | - * |
|
| 20 | - * This method must always return an array. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function getJsonValue() |
|
| 25 | - { |
|
| 26 | - return [$this->getRawMimeDirValue()]; |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * Returns the value, in the format it should be encoded for json. |
|
| 19 | + * |
|
| 20 | + * This method must always return an array. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function getJsonValue() |
|
| 25 | + { |
|
| 26 | + return [$this->getRawMimeDirValue()]; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns the type of value. |
|
| 31 | - * |
|
| 32 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
| 33 | - * 'default' valueType. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getValueType() |
|
| 38 | - { |
|
| 39 | - return 'UNKNOWN'; |
|
| 40 | - } |
|
| 29 | + /** |
|
| 30 | + * Returns the type of value. |
|
| 31 | + * |
|
| 32 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
| 33 | + * 'default' valueType. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getValueType() |
|
| 38 | + { |
|
| 39 | + return 'UNKNOWN'; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -20,90 +20,90 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Binary extends Property |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * In case this is a multi-value property. This string will be used as a |
|
| 25 | - * delimiter. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public $delimiter = ''; |
|
| 23 | + /** |
|
| 24 | + * In case this is a multi-value property. This string will be used as a |
|
| 25 | + * delimiter. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public $delimiter = ''; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Updates the current value. |
|
| 33 | - * |
|
| 34 | - * This may be either a single, or multiple strings in an array. |
|
| 35 | - * |
|
| 36 | - * @param string|array $value |
|
| 37 | - */ |
|
| 38 | - public function setValue($value) |
|
| 39 | - { |
|
| 40 | - if (is_array($value)) { |
|
| 41 | - if (1 === count($value)) { |
|
| 42 | - $this->value = $value[0]; |
|
| 43 | - } else { |
|
| 44 | - throw new \InvalidArgumentException('The argument must either be a string or an array with only one child'); |
|
| 45 | - } |
|
| 46 | - } else { |
|
| 47 | - $this->value = $value; |
|
| 48 | - } |
|
| 49 | - } |
|
| 31 | + /** |
|
| 32 | + * Updates the current value. |
|
| 33 | + * |
|
| 34 | + * This may be either a single, or multiple strings in an array. |
|
| 35 | + * |
|
| 36 | + * @param string|array $value |
|
| 37 | + */ |
|
| 38 | + public function setValue($value) |
|
| 39 | + { |
|
| 40 | + if (is_array($value)) { |
|
| 41 | + if (1 === count($value)) { |
|
| 42 | + $this->value = $value[0]; |
|
| 43 | + } else { |
|
| 44 | + throw new \InvalidArgumentException('The argument must either be a string or an array with only one child'); |
|
| 45 | + } |
|
| 46 | + } else { |
|
| 47 | + $this->value = $value; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 53 | - * |
|
| 54 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 55 | - * not yet done, but parameters are not included. |
|
| 56 | - * |
|
| 57 | - * @param string $val |
|
| 58 | - */ |
|
| 59 | - public function setRawMimeDirValue($val) |
|
| 60 | - { |
|
| 61 | - $this->value = base64_decode($val); |
|
| 62 | - } |
|
| 51 | + /** |
|
| 52 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 53 | + * |
|
| 54 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 55 | + * not yet done, but parameters are not included. |
|
| 56 | + * |
|
| 57 | + * @param string $val |
|
| 58 | + */ |
|
| 59 | + public function setRawMimeDirValue($val) |
|
| 60 | + { |
|
| 61 | + $this->value = base64_decode($val); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Returns a raw mime-dir representation of the value. |
|
| 66 | - * |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function getRawMimeDirValue() |
|
| 70 | - { |
|
| 71 | - return base64_encode($this->value); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Returns a raw mime-dir representation of the value. |
|
| 66 | + * |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function getRawMimeDirValue() |
|
| 70 | + { |
|
| 71 | + return base64_encode($this->value); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Returns the type of value. |
|
| 76 | - * |
|
| 77 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
| 78 | - * 'default' valueType. |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getValueType() |
|
| 83 | - { |
|
| 84 | - return 'BINARY'; |
|
| 85 | - } |
|
| 74 | + /** |
|
| 75 | + * Returns the type of value. |
|
| 76 | + * |
|
| 77 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
| 78 | + * 'default' valueType. |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getValueType() |
|
| 83 | + { |
|
| 84 | + return 'BINARY'; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns the value, in the format it should be encoded for json. |
|
| 89 | - * |
|
| 90 | - * This method must always return an array. |
|
| 91 | - * |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - public function getJsonValue() |
|
| 95 | - { |
|
| 96 | - return [base64_encode($this->getValue())]; |
|
| 97 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns the value, in the format it should be encoded for json. |
|
| 89 | + * |
|
| 90 | + * This method must always return an array. |
|
| 91 | + * |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + public function getJsonValue() |
|
| 95 | + { |
|
| 96 | + return [base64_encode($this->getValue())]; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Sets the json value, as it would appear in a jCard or jCal object. |
|
| 101 | - * |
|
| 102 | - * The value must always be an array. |
|
| 103 | - */ |
|
| 104 | - public function setJsonValue(array $value) |
|
| 105 | - { |
|
| 106 | - $value = array_map('base64_decode', $value); |
|
| 107 | - parent::setJsonValue($value); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * Sets the json value, as it would appear in a jCard or jCal object. |
|
| 101 | + * |
|
| 102 | + * The value must always be an array. |
|
| 103 | + */ |
|
| 104 | + public function setJsonValue(array $value) |
|
| 105 | + { |
|
| 106 | + $value = array_map('base64_decode', $value); |
|
| 107 | + parent::setJsonValue($value); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -16,61 +16,61 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class IntegerValue extends Property |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 21 | - * |
|
| 22 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 23 | - * not yet done, but parameters are not included. |
|
| 24 | - * |
|
| 25 | - * @param string $val |
|
| 26 | - */ |
|
| 27 | - public function setRawMimeDirValue($val) |
|
| 28 | - { |
|
| 29 | - $this->setValue((int) $val); |
|
| 30 | - } |
|
| 19 | + /** |
|
| 20 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 21 | + * |
|
| 22 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 23 | + * not yet done, but parameters are not included. |
|
| 24 | + * |
|
| 25 | + * @param string $val |
|
| 26 | + */ |
|
| 27 | + public function setRawMimeDirValue($val) |
|
| 28 | + { |
|
| 29 | + $this->setValue((int) $val); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Returns a raw mime-dir representation of the value. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getRawMimeDirValue() |
|
| 38 | - { |
|
| 39 | - return $this->value; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * Returns a raw mime-dir representation of the value. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getRawMimeDirValue() |
|
| 38 | + { |
|
| 39 | + return $this->value; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Returns the type of value. |
|
| 44 | - * |
|
| 45 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
| 46 | - * 'default' valueType. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function getValueType() |
|
| 51 | - { |
|
| 52 | - return 'INTEGER'; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * Returns the type of value. |
|
| 44 | + * |
|
| 45 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
| 46 | + * 'default' valueType. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function getValueType() |
|
| 51 | + { |
|
| 52 | + return 'INTEGER'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns the value, in the format it should be encoded for json. |
|
| 57 | - * |
|
| 58 | - * This method must always return an array. |
|
| 59 | - * |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function getJsonValue() |
|
| 63 | - { |
|
| 64 | - return [(int) $this->getValue()]; |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * Returns the value, in the format it should be encoded for json. |
|
| 57 | + * |
|
| 58 | + * This method must always return an array. |
|
| 59 | + * |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function getJsonValue() |
|
| 63 | + { |
|
| 64 | + return [(int) $this->getValue()]; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
| 69 | - * object. |
|
| 70 | - */ |
|
| 71 | - public function setXmlValue(array $value) |
|
| 72 | - { |
|
| 73 | - $value = array_map('intval', $value); |
|
| 74 | - parent::setXmlValue($value); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
|
| 69 | + * object. |
|
| 70 | + */ |
|
| 71 | + public function setXmlValue(array $value) |
|
| 72 | + { |
|
| 73 | + $value = array_map('intval', $value); |
|
| 74 | + parent::setXmlValue($value); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -19,374 +19,374 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Text 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 = ','; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * List of properties that are considered 'structured'. |
|
| 32 | - * |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $structuredValues = [ |
|
| 36 | - // vCard |
|
| 37 | - 'N', |
|
| 38 | - 'ADR', |
|
| 39 | - 'ORG', |
|
| 40 | - 'GENDER', |
|
| 41 | - 'CLIENTPIDMAP', |
|
| 42 | - |
|
| 43 | - // iCalendar |
|
| 44 | - 'REQUEST-STATUS', |
|
| 45 | - ]; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Some text components have a minimum number of components. |
|
| 49 | - * |
|
| 50 | - * N must for instance be represented as 5 components, separated by ;, even |
|
| 51 | - * if the last few components are unused. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $minimumPropertyValues = [ |
|
| 56 | - 'N' => 5, |
|
| 57 | - 'ADR' => 7, |
|
| 58 | - ]; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Creates the property. |
|
| 62 | - * |
|
| 63 | - * You can specify the parameters either in key=>value syntax, in which case |
|
| 64 | - * parameters will automatically be created, or you can just pass a list of |
|
| 65 | - * Parameter objects. |
|
| 66 | - * |
|
| 67 | - * @param Component $root The root document |
|
| 68 | - * @param string $name |
|
| 69 | - * @param string|array|null $value |
|
| 70 | - * @param array $parameters List of parameters |
|
| 71 | - * @param string $group The vcard property group |
|
| 72 | - */ |
|
| 73 | - public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) |
|
| 74 | - { |
|
| 75 | - // There's two types of multi-valued text properties: |
|
| 76 | - // 1. multivalue properties. |
|
| 77 | - // 2. structured value properties |
|
| 78 | - // |
|
| 79 | - // The former is always separated by a comma, the latter by semi-colon. |
|
| 80 | - if (in_array($name, $this->structuredValues)) { |
|
| 81 | - $this->delimiter = ';'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - parent::__construct($root, $name, $value, $parameters, $group); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 89 | - * |
|
| 90 | - * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 91 | - * not yet done, but parameters are not included. |
|
| 92 | - * |
|
| 93 | - * @param string $val |
|
| 94 | - */ |
|
| 95 | - public function setRawMimeDirValue($val) |
|
| 96 | - { |
|
| 97 | - $this->setValue(MimeDir::unescapeValue($val, $this->delimiter)); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Sets the value as a quoted-printable encoded string. |
|
| 102 | - * |
|
| 103 | - * @param string $val |
|
| 104 | - */ |
|
| 105 | - public function setQuotedPrintableValue($val) |
|
| 106 | - { |
|
| 107 | - $val = quoted_printable_decode($val); |
|
| 108 | - |
|
| 109 | - // Quoted printable only appears in vCard 2.1, and the only character |
|
| 110 | - // that may be escaped there is ;. So we are simply splitting on just |
|
| 111 | - // that. |
|
| 112 | - // |
|
| 113 | - // We also don't have to unescape \\, so all we need to look for is a ; |
|
| 114 | - // that's not preceded with a \. |
|
| 115 | - $regex = '# (?<!\\\\) ; #x'; |
|
| 116 | - $matches = preg_split($regex, $val); |
|
| 117 | - $this->setValue($matches); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Returns a raw mime-dir representation of the value. |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function getRawMimeDirValue() |
|
| 126 | - { |
|
| 127 | - $val = $this->getParts(); |
|
| 128 | - |
|
| 129 | - if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 130 | - $val = array_pad($val, $this->minimumPropertyValues[$this->name], ''); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - foreach ($val as &$item) { |
|
| 134 | - if (!is_array($item)) { |
|
| 135 | - $item = [$item]; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - foreach ($item as &$subItem) { |
|
| 139 | - if (!is_null($subItem)) { |
|
| 140 | - $subItem = strtr( |
|
| 141 | - $subItem, |
|
| 142 | - [ |
|
| 143 | - '\\' => '\\\\', |
|
| 144 | - ';' => '\;', |
|
| 145 | - ',' => '\,', |
|
| 146 | - "\n" => '\n', |
|
| 147 | - "\r" => '', |
|
| 148 | - ] |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $item = implode(',', $item); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return implode($this->delimiter, $val); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Returns the value, in the format it should be encoded for json. |
|
| 160 | - * |
|
| 161 | - * This method must always return an array. |
|
| 162 | - * |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function getJsonValue() |
|
| 166 | - { |
|
| 167 | - // Structured text values should always be returned as a single |
|
| 168 | - // array-item. Multi-value text should be returned as multiple items in |
|
| 169 | - // the top-array. |
|
| 170 | - if (in_array($this->name, $this->structuredValues)) { |
|
| 171 | - return [$this->getParts()]; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $this->getParts(); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Returns the type of value. |
|
| 179 | - * |
|
| 180 | - * This corresponds to the VALUE= parameter. Every property also has a |
|
| 181 | - * 'default' valueType. |
|
| 182 | - * |
|
| 183 | - * @return string |
|
| 184 | - */ |
|
| 185 | - public function getValueType() |
|
| 186 | - { |
|
| 187 | - return 'TEXT'; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Turns the object back into a serialized blob. |
|
| 192 | - * |
|
| 193 | - * @return string |
|
| 194 | - */ |
|
| 195 | - public function serialize() |
|
| 196 | - { |
|
| 197 | - // We need to kick in a special type of encoding, if it's a 2.1 vcard. |
|
| 198 | - if (Document::VCARD21 !== $this->root->getDocumentType()) { |
|
| 199 | - return parent::serialize(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $val = $this->getParts(); |
|
| 203 | - |
|
| 204 | - if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 205 | - $val = \array_pad($val, $this->minimumPropertyValues[$this->name], ''); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // Imploding multiple parts into a single value, and splitting the |
|
| 209 | - // values with ;. |
|
| 210 | - if (\count($val) > 1) { |
|
| 211 | - foreach ($val as $k => $v) { |
|
| 212 | - $val[$k] = \str_replace(';', '\;', $v); |
|
| 213 | - } |
|
| 214 | - $val = \implode(';', $val); |
|
| 215 | - } else { |
|
| 216 | - $val = $val[0]; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $str = $this->name; |
|
| 220 | - if ($this->group) { |
|
| 221 | - $str = $this->group.'.'.$this->name; |
|
| 222 | - } |
|
| 223 | - foreach ($this->parameters as $param) { |
|
| 224 | - if ('QUOTED-PRINTABLE' === $param->getValue()) { |
|
| 225 | - continue; |
|
| 226 | - } |
|
| 227 | - $str .= ';'.$param->serialize(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // If the resulting value contains a \n, we must encode it as |
|
| 231 | - // quoted-printable. |
|
| 232 | - if (false !== \strpos($val, "\n")) { |
|
| 233 | - $str .= ';ENCODING=QUOTED-PRINTABLE:'; |
|
| 234 | - $lastLine = $str; |
|
| 235 | - $out = null; |
|
| 236 | - |
|
| 237 | - // The PHP built-in quoted-printable-encode does not correctly |
|
| 238 | - // encode newlines for us. Specifically, the \r\n sequence must in |
|
| 239 | - // vcards be encoded as =0D=OA and we must insert soft-newlines |
|
| 240 | - // every 75 bytes. |
|
| 241 | - for ($ii = 0; $ii < \strlen($val); ++$ii) { |
|
| 242 | - $ord = \ord($val[$ii]); |
|
| 243 | - // These characters are encoded as themselves. |
|
| 244 | - if ($ord >= 32 && $ord <= 126) { |
|
| 245 | - $lastLine .= $val[$ii]; |
|
| 246 | - } else { |
|
| 247 | - $lastLine .= '='.\strtoupper(\bin2hex($val[$ii])); |
|
| 248 | - } |
|
| 249 | - if (\strlen($lastLine) >= 75) { |
|
| 250 | - // Soft line break |
|
| 251 | - $out .= $lastLine."=\r\n "; |
|
| 252 | - $lastLine = null; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - if (!\is_null($lastLine)) { |
|
| 256 | - $out .= $lastLine."\r\n"; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $out; |
|
| 260 | - } else { |
|
| 261 | - $str .= ':'.$val; |
|
| 262 | - |
|
| 263 | - $str = \preg_replace( |
|
| 264 | - '/( |
|
| 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 | + |
|
| 30 | + /** |
|
| 31 | + * List of properties that are considered 'structured'. |
|
| 32 | + * |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $structuredValues = [ |
|
| 36 | + // vCard |
|
| 37 | + 'N', |
|
| 38 | + 'ADR', |
|
| 39 | + 'ORG', |
|
| 40 | + 'GENDER', |
|
| 41 | + 'CLIENTPIDMAP', |
|
| 42 | + |
|
| 43 | + // iCalendar |
|
| 44 | + 'REQUEST-STATUS', |
|
| 45 | + ]; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Some text components have a minimum number of components. |
|
| 49 | + * |
|
| 50 | + * N must for instance be represented as 5 components, separated by ;, even |
|
| 51 | + * if the last few components are unused. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $minimumPropertyValues = [ |
|
| 56 | + 'N' => 5, |
|
| 57 | + 'ADR' => 7, |
|
| 58 | + ]; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Creates the property. |
|
| 62 | + * |
|
| 63 | + * You can specify the parameters either in key=>value syntax, in which case |
|
| 64 | + * parameters will automatically be created, or you can just pass a list of |
|
| 65 | + * Parameter objects. |
|
| 66 | + * |
|
| 67 | + * @param Component $root The root document |
|
| 68 | + * @param string $name |
|
| 69 | + * @param string|array|null $value |
|
| 70 | + * @param array $parameters List of parameters |
|
| 71 | + * @param string $group The vcard property group |
|
| 72 | + */ |
|
| 73 | + public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) |
|
| 74 | + { |
|
| 75 | + // There's two types of multi-valued text properties: |
|
| 76 | + // 1. multivalue properties. |
|
| 77 | + // 2. structured value properties |
|
| 78 | + // |
|
| 79 | + // The former is always separated by a comma, the latter by semi-colon. |
|
| 80 | + if (in_array($name, $this->structuredValues)) { |
|
| 81 | + $this->delimiter = ';'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + parent::__construct($root, $name, $value, $parameters, $group); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
|
| 89 | + * |
|
| 90 | + * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
|
| 91 | + * not yet done, but parameters are not included. |
|
| 92 | + * |
|
| 93 | + * @param string $val |
|
| 94 | + */ |
|
| 95 | + public function setRawMimeDirValue($val) |
|
| 96 | + { |
|
| 97 | + $this->setValue(MimeDir::unescapeValue($val, $this->delimiter)); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Sets the value as a quoted-printable encoded string. |
|
| 102 | + * |
|
| 103 | + * @param string $val |
|
| 104 | + */ |
|
| 105 | + public function setQuotedPrintableValue($val) |
|
| 106 | + { |
|
| 107 | + $val = quoted_printable_decode($val); |
|
| 108 | + |
|
| 109 | + // Quoted printable only appears in vCard 2.1, and the only character |
|
| 110 | + // that may be escaped there is ;. So we are simply splitting on just |
|
| 111 | + // that. |
|
| 112 | + // |
|
| 113 | + // We also don't have to unescape \\, so all we need to look for is a ; |
|
| 114 | + // that's not preceded with a \. |
|
| 115 | + $regex = '# (?<!\\\\) ; #x'; |
|
| 116 | + $matches = preg_split($regex, $val); |
|
| 117 | + $this->setValue($matches); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Returns a raw mime-dir representation of the value. |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function getRawMimeDirValue() |
|
| 126 | + { |
|
| 127 | + $val = $this->getParts(); |
|
| 128 | + |
|
| 129 | + if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 130 | + $val = array_pad($val, $this->minimumPropertyValues[$this->name], ''); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + foreach ($val as &$item) { |
|
| 134 | + if (!is_array($item)) { |
|
| 135 | + $item = [$item]; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + foreach ($item as &$subItem) { |
|
| 139 | + if (!is_null($subItem)) { |
|
| 140 | + $subItem = strtr( |
|
| 141 | + $subItem, |
|
| 142 | + [ |
|
| 143 | + '\\' => '\\\\', |
|
| 144 | + ';' => '\;', |
|
| 145 | + ',' => '\,', |
|
| 146 | + "\n" => '\n', |
|
| 147 | + "\r" => '', |
|
| 148 | + ] |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $item = implode(',', $item); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return implode($this->delimiter, $val); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Returns the value, in the format it should be encoded for json. |
|
| 160 | + * |
|
| 161 | + * This method must always return an array. |
|
| 162 | + * |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function getJsonValue() |
|
| 166 | + { |
|
| 167 | + // Structured text values should always be returned as a single |
|
| 168 | + // array-item. Multi-value text should be returned as multiple items in |
|
| 169 | + // the top-array. |
|
| 170 | + if (in_array($this->name, $this->structuredValues)) { |
|
| 171 | + return [$this->getParts()]; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $this->getParts(); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Returns the type of value. |
|
| 179 | + * |
|
| 180 | + * This corresponds to the VALUE= parameter. Every property also has a |
|
| 181 | + * 'default' valueType. |
|
| 182 | + * |
|
| 183 | + * @return string |
|
| 184 | + */ |
|
| 185 | + public function getValueType() |
|
| 186 | + { |
|
| 187 | + return 'TEXT'; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Turns the object back into a serialized blob. |
|
| 192 | + * |
|
| 193 | + * @return string |
|
| 194 | + */ |
|
| 195 | + public function serialize() |
|
| 196 | + { |
|
| 197 | + // We need to kick in a special type of encoding, if it's a 2.1 vcard. |
|
| 198 | + if (Document::VCARD21 !== $this->root->getDocumentType()) { |
|
| 199 | + return parent::serialize(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $val = $this->getParts(); |
|
| 203 | + |
|
| 204 | + if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 205 | + $val = \array_pad($val, $this->minimumPropertyValues[$this->name], ''); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // Imploding multiple parts into a single value, and splitting the |
|
| 209 | + // values with ;. |
|
| 210 | + if (\count($val) > 1) { |
|
| 211 | + foreach ($val as $k => $v) { |
|
| 212 | + $val[$k] = \str_replace(';', '\;', $v); |
|
| 213 | + } |
|
| 214 | + $val = \implode(';', $val); |
|
| 215 | + } else { |
|
| 216 | + $val = $val[0]; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $str = $this->name; |
|
| 220 | + if ($this->group) { |
|
| 221 | + $str = $this->group.'.'.$this->name; |
|
| 222 | + } |
|
| 223 | + foreach ($this->parameters as $param) { |
|
| 224 | + if ('QUOTED-PRINTABLE' === $param->getValue()) { |
|
| 225 | + continue; |
|
| 226 | + } |
|
| 227 | + $str .= ';'.$param->serialize(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // If the resulting value contains a \n, we must encode it as |
|
| 231 | + // quoted-printable. |
|
| 232 | + if (false !== \strpos($val, "\n")) { |
|
| 233 | + $str .= ';ENCODING=QUOTED-PRINTABLE:'; |
|
| 234 | + $lastLine = $str; |
|
| 235 | + $out = null; |
|
| 236 | + |
|
| 237 | + // The PHP built-in quoted-printable-encode does not correctly |
|
| 238 | + // encode newlines for us. Specifically, the \r\n sequence must in |
|
| 239 | + // vcards be encoded as =0D=OA and we must insert soft-newlines |
|
| 240 | + // every 75 bytes. |
|
| 241 | + for ($ii = 0; $ii < \strlen($val); ++$ii) { |
|
| 242 | + $ord = \ord($val[$ii]); |
|
| 243 | + // These characters are encoded as themselves. |
|
| 244 | + if ($ord >= 32 && $ord <= 126) { |
|
| 245 | + $lastLine .= $val[$ii]; |
|
| 246 | + } else { |
|
| 247 | + $lastLine .= '='.\strtoupper(\bin2hex($val[$ii])); |
|
| 248 | + } |
|
| 249 | + if (\strlen($lastLine) >= 75) { |
|
| 250 | + // Soft line break |
|
| 251 | + $out .= $lastLine."=\r\n "; |
|
| 252 | + $lastLine = null; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + if (!\is_null($lastLine)) { |
|
| 256 | + $out .= $lastLine."\r\n"; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $out; |
|
| 260 | + } else { |
|
| 261 | + $str .= ':'.$val; |
|
| 262 | + |
|
| 263 | + $str = \preg_replace( |
|
| 264 | + '/( |
|
| 265 | 265 | (?:^.)? # 1 additional byte in first line because of missing single space (see next line) |
| 266 | 266 | .{1,74} # max 75 bytes per line (1 byte is used for a single space added after every CRLF) |
| 267 | 267 | (?![\x80-\xbf]) # prevent splitting multibyte characters |
| 268 | 268 | )/x', |
| 269 | - "$1\r\n ", |
|
| 270 | - $str |
|
| 271 | - ); |
|
| 272 | - |
|
| 273 | - // remove single space after last CRLF |
|
| 274 | - return \substr($str, 0, -1); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * This method serializes only the value of a property. This is used to |
|
| 280 | - * create xCard or xCal documents. |
|
| 281 | - * |
|
| 282 | - * @param Xml\Writer $writer XML writer |
|
| 283 | - */ |
|
| 284 | - protected function xmlSerializeValue(Xml\Writer $writer) |
|
| 285 | - { |
|
| 286 | - $values = $this->getParts(); |
|
| 287 | - |
|
| 288 | - $map = function ($items) use ($values, $writer) { |
|
| 289 | - foreach ($items as $i => $item) { |
|
| 290 | - $writer->writeElement( |
|
| 291 | - $item, |
|
| 292 | - !empty($values[$i]) ? $values[$i] : null |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - }; |
|
| 296 | - |
|
| 297 | - switch ($this->name) { |
|
| 298 | - // Special-casing the REQUEST-STATUS property. |
|
| 299 | - // |
|
| 300 | - // See: |
|
| 301 | - // http://tools.ietf.org/html/rfc6321#section-3.4.1.3 |
|
| 302 | - case 'REQUEST-STATUS': |
|
| 303 | - $writer->writeElement('code', $values[0]); |
|
| 304 | - $writer->writeElement('description', $values[1]); |
|
| 305 | - |
|
| 306 | - if (isset($values[2])) { |
|
| 307 | - $writer->writeElement('data', $values[2]); |
|
| 308 | - } |
|
| 309 | - break; |
|
| 310 | - |
|
| 311 | - case 'N': |
|
| 312 | - $map([ |
|
| 313 | - 'surname', |
|
| 314 | - 'given', |
|
| 315 | - 'additional', |
|
| 316 | - 'prefix', |
|
| 317 | - 'suffix', |
|
| 318 | - ]); |
|
| 319 | - break; |
|
| 320 | - |
|
| 321 | - case 'GENDER': |
|
| 322 | - $map([ |
|
| 323 | - 'sex', |
|
| 324 | - 'text', |
|
| 325 | - ]); |
|
| 326 | - break; |
|
| 327 | - |
|
| 328 | - case 'ADR': |
|
| 329 | - $map([ |
|
| 330 | - 'pobox', |
|
| 331 | - 'ext', |
|
| 332 | - 'street', |
|
| 333 | - 'locality', |
|
| 334 | - 'region', |
|
| 335 | - 'code', |
|
| 336 | - 'country', |
|
| 337 | - ]); |
|
| 338 | - break; |
|
| 339 | - |
|
| 340 | - case 'CLIENTPIDMAP': |
|
| 341 | - $map([ |
|
| 342 | - 'sourceid', |
|
| 343 | - 'uri', |
|
| 344 | - ]); |
|
| 345 | - break; |
|
| 346 | - |
|
| 347 | - default: |
|
| 348 | - parent::xmlSerializeValue($writer); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Validates the node for correctness. |
|
| 354 | - * |
|
| 355 | - * The following options are supported: |
|
| 356 | - * - Node::REPAIR - If something is broken, and automatic repair may |
|
| 357 | - * be attempted. |
|
| 358 | - * |
|
| 359 | - * An array is returned with warnings. |
|
| 360 | - * |
|
| 361 | - * Every item in the array has the following properties: |
|
| 362 | - * * level - (number between 1 and 3 with severity information) |
|
| 363 | - * * message - (human readable message) |
|
| 364 | - * * node - (reference to the offending node) |
|
| 365 | - * |
|
| 366 | - * @param int $options |
|
| 367 | - * |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - public function validate($options = 0) |
|
| 371 | - { |
|
| 372 | - $warnings = parent::validate($options); |
|
| 373 | - |
|
| 374 | - if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 375 | - $minimum = $this->minimumPropertyValues[$this->name]; |
|
| 376 | - $parts = $this->getParts(); |
|
| 377 | - if (count($parts) < $minimum) { |
|
| 378 | - $warnings[] = [ |
|
| 379 | - 'level' => $options & self::REPAIR ? 1 : 3, |
|
| 380 | - 'message' => 'The '.$this->name.' property must have at least '.$minimum.' values. It only has '.count($parts), |
|
| 381 | - 'node' => $this, |
|
| 382 | - ]; |
|
| 383 | - if ($options & self::REPAIR) { |
|
| 384 | - $parts = array_pad($parts, $minimum, ''); |
|
| 385 | - $this->setParts($parts); |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - return $warnings; |
|
| 391 | - } |
|
| 269 | + "$1\r\n ", |
|
| 270 | + $str |
|
| 271 | + ); |
|
| 272 | + |
|
| 273 | + // remove single space after last CRLF |
|
| 274 | + return \substr($str, 0, -1); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * This method serializes only the value of a property. This is used to |
|
| 280 | + * create xCard or xCal documents. |
|
| 281 | + * |
|
| 282 | + * @param Xml\Writer $writer XML writer |
|
| 283 | + */ |
|
| 284 | + protected function xmlSerializeValue(Xml\Writer $writer) |
|
| 285 | + { |
|
| 286 | + $values = $this->getParts(); |
|
| 287 | + |
|
| 288 | + $map = function ($items) use ($values, $writer) { |
|
| 289 | + foreach ($items as $i => $item) { |
|
| 290 | + $writer->writeElement( |
|
| 291 | + $item, |
|
| 292 | + !empty($values[$i]) ? $values[$i] : null |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + }; |
|
| 296 | + |
|
| 297 | + switch ($this->name) { |
|
| 298 | + // Special-casing the REQUEST-STATUS property. |
|
| 299 | + // |
|
| 300 | + // See: |
|
| 301 | + // http://tools.ietf.org/html/rfc6321#section-3.4.1.3 |
|
| 302 | + case 'REQUEST-STATUS': |
|
| 303 | + $writer->writeElement('code', $values[0]); |
|
| 304 | + $writer->writeElement('description', $values[1]); |
|
| 305 | + |
|
| 306 | + if (isset($values[2])) { |
|
| 307 | + $writer->writeElement('data', $values[2]); |
|
| 308 | + } |
|
| 309 | + break; |
|
| 310 | + |
|
| 311 | + case 'N': |
|
| 312 | + $map([ |
|
| 313 | + 'surname', |
|
| 314 | + 'given', |
|
| 315 | + 'additional', |
|
| 316 | + 'prefix', |
|
| 317 | + 'suffix', |
|
| 318 | + ]); |
|
| 319 | + break; |
|
| 320 | + |
|
| 321 | + case 'GENDER': |
|
| 322 | + $map([ |
|
| 323 | + 'sex', |
|
| 324 | + 'text', |
|
| 325 | + ]); |
|
| 326 | + break; |
|
| 327 | + |
|
| 328 | + case 'ADR': |
|
| 329 | + $map([ |
|
| 330 | + 'pobox', |
|
| 331 | + 'ext', |
|
| 332 | + 'street', |
|
| 333 | + 'locality', |
|
| 334 | + 'region', |
|
| 335 | + 'code', |
|
| 336 | + 'country', |
|
| 337 | + ]); |
|
| 338 | + break; |
|
| 339 | + |
|
| 340 | + case 'CLIENTPIDMAP': |
|
| 341 | + $map([ |
|
| 342 | + 'sourceid', |
|
| 343 | + 'uri', |
|
| 344 | + ]); |
|
| 345 | + break; |
|
| 346 | + |
|
| 347 | + default: |
|
| 348 | + parent::xmlSerializeValue($writer); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Validates the node for correctness. |
|
| 354 | + * |
|
| 355 | + * The following options are supported: |
|
| 356 | + * - Node::REPAIR - If something is broken, and automatic repair may |
|
| 357 | + * be attempted. |
|
| 358 | + * |
|
| 359 | + * An array is returned with warnings. |
|
| 360 | + * |
|
| 361 | + * Every item in the array has the following properties: |
|
| 362 | + * * level - (number between 1 and 3 with severity information) |
|
| 363 | + * * message - (human readable message) |
|
| 364 | + * * node - (reference to the offending node) |
|
| 365 | + * |
|
| 366 | + * @param int $options |
|
| 367 | + * |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + public function validate($options = 0) |
|
| 371 | + { |
|
| 372 | + $warnings = parent::validate($options); |
|
| 373 | + |
|
| 374 | + if (isset($this->minimumPropertyValues[$this->name])) { |
|
| 375 | + $minimum = $this->minimumPropertyValues[$this->name]; |
|
| 376 | + $parts = $this->getParts(); |
|
| 377 | + if (count($parts) < $minimum) { |
|
| 378 | + $warnings[] = [ |
|
| 379 | + 'level' => $options & self::REPAIR ? 1 : 3, |
|
| 380 | + 'message' => 'The '.$this->name.' property must have at least '.$minimum.' values. It only has '.count($parts), |
|
| 381 | + 'node' => $this, |
|
| 382 | + ]; |
|
| 383 | + if ($options & self::REPAIR) { |
|
| 384 | + $parts = array_pad($parts, $minimum, ''); |
|
| 385 | + $this->setParts($parts); |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + return $warnings; |
|
| 391 | + } |
|
| 392 | 392 | } |
@@ -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 | } |