Completed
Push — developer ( d751a3...e1a3df )
by Błażej
164:44 queued 111:37
created
libraries/SabreDAV/VObject/Property/IntegerValue.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace Sabre\VObject\Property;
4 4
 
5 5
 use
6
-    Sabre\VObject\Property;
6
+	Sabre\VObject\Property;
7 7
 
8 8
 /**
9 9
  * Integer property.
@@ -17,72 +17,72 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class IntegerValue extends Property {
19 19
 
20
-    /**
21
-     * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
22
-     *
23
-     * This has been 'unfolded', so only 1 line will be passed. Unescaping is
24
-     * not yet done, but parameters are not included.
25
-     *
26
-     * @param string $val
27
-     *
28
-     * @return void
29
-     */
30
-    public function setRawMimeDirValue($val) {
31
-
32
-        $this->setValue((int)$val);
33
-
34
-    }
35
-
36
-    /**
37
-     * Returns a raw mime-dir representation of the value.
38
-     *
39
-     * @return string
40
-     */
41
-    public function getRawMimeDirValue() {
42
-
43
-        return $this->value;
44
-
45
-    }
46
-
47
-    /**
48
-     * Returns the type of value.
49
-     *
50
-     * This corresponds to the VALUE= parameter. Every property also has a
51
-     * 'default' valueType.
52
-     *
53
-     * @return string
54
-     */
55
-    public function getValueType() {
56
-
57
-        return 'INTEGER';
58
-
59
-    }
60
-
61
-    /**
62
-     * Returns the value, in the format it should be encoded for json.
63
-     *
64
-     * This method must always return an array.
65
-     *
66
-     * @return array
67
-     */
68
-    public function getJsonValue() {
69
-
70
-        return [(int)$this->getValue()];
71
-
72
-    }
73
-
74
-    /**
75
-     * Hydrate data from a XML subtree, as it would appear in a xCard or xCal
76
-     * object.
77
-     *
78
-     * @param array $value
79
-     *
80
-     * @return void
81
-     */
82
-    public function setXmlValue(array $value) {
83
-
84
-        $value = array_map('intval', $value);
85
-        parent::setXmlValue($value);
86
-
87
-    }
20
+	/**
21
+	 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
22
+	 *
23
+	 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
24
+	 * not yet done, but parameters are not included.
25
+	 *
26
+	 * @param string $val
27
+	 *
28
+	 * @return void
29
+	 */
30
+	public function setRawMimeDirValue($val) {
31
+
32
+		$this->setValue((int)$val);
33
+
34
+	}
35
+
36
+	/**
37
+	 * Returns a raw mime-dir representation of the value.
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function getRawMimeDirValue() {
42
+
43
+		return $this->value;
44
+
45
+	}
46
+
47
+	/**
48
+	 * Returns the type of value.
49
+	 *
50
+	 * This corresponds to the VALUE= parameter. Every property also has a
51
+	 * 'default' valueType.
52
+	 *
53
+	 * @return string
54
+	 */
55
+	public function getValueType() {
56
+
57
+		return 'INTEGER';
58
+
59
+	}
60
+
61
+	/**
62
+	 * Returns the value, in the format it should be encoded for json.
63
+	 *
64
+	 * This method must always return an array.
65
+	 *
66
+	 * @return array
67
+	 */
68
+	public function getJsonValue() {
69
+
70
+		return [(int)$this->getValue()];
71
+
72
+	}
73
+
74
+	/**
75
+	 * Hydrate data from a XML subtree, as it would appear in a xCard or xCal
76
+	 * object.
77
+	 *
78
+	 * @param array $value
79
+	 *
80
+	 * @return void
81
+	 */
82
+	public function setXmlValue(array $value) {
83
+
84
+		$value = array_map('intval', $value);
85
+		parent::setXmlValue($value);
86
+
87
+	}
88 88
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/FloatValue.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -17,126 +17,126 @@
 block discarded – undo
17 17
  */
18 18
 class FloatValue extends Property {
19 19
 
20
-    /**
21
-     * In case this is a multi-value property. This string will be used as a
22
-     * delimiter.
23
-     *
24
-     * @var string|null
25
-     */
26
-    public $delimiter = ';';
27
-
28
-    /**
29
-     * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
30
-     *
31
-     * This has been 'unfolded', so only 1 line will be passed. Unescaping is
32
-     * not yet done, but parameters are not included.
33
-     *
34
-     * @param string $val
35
-     *
36
-     * @return void
37
-     */
38
-    public function setRawMimeDirValue($val) {
39
-
40
-        $val = explode($this->delimiter, $val);
41
-        foreach ($val as &$item) {
42
-            $item = (float)$item;
43
-        }
44
-        $this->setParts($val);
45
-
46
-    }
47
-
48
-    /**
49
-     * Returns a raw mime-dir representation of the value.
50
-     *
51
-     * @return string
52
-     */
53
-    public function getRawMimeDirValue() {
54
-
55
-        return implode(
56
-            $this->delimiter,
57
-            $this->getParts()
58
-        );
59
-
60
-    }
61
-
62
-    /**
63
-     * Returns the type of value.
64
-     *
65
-     * This corresponds to the VALUE= parameter. Every property also has a
66
-     * 'default' valueType.
67
-     *
68
-     * @return string
69
-     */
70
-    public function getValueType() {
71
-
72
-        return 'FLOAT';
73
-
74
-    }
75
-
76
-    /**
77
-     * Returns the value, in the format it should be encoded for JSON.
78
-     *
79
-     * This method must always return an array.
80
-     *
81
-     * @return array
82
-     */
83
-    public function getJsonValue() {
84
-
85
-        $val = array_map('floatval', $this->getParts());
86
-
87
-        // Special-casing the GEO property.
88
-        //
89
-        // See:
90
-        // http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
91
-        if ($this->name === 'GEO') {
92
-            return [$val];
93
-        }
94
-
95
-        return $val;
96
-
97
-    }
98
-
99
-    /**
100
-     * Hydrate data from a XML subtree, as it would appear in a xCard or xCal
101
-     * object.
102
-     *
103
-     * @param array $value
104
-     *
105
-     * @return void
106
-     */
107
-    public function setXmlValue(array $value) {
108
-
109
-        $value = array_map('floatval', $value);
110
-        parent::setXmlValue($value);
111
-
112
-    }
113
-
114
-    /**
115
-     * This method serializes only the value of a property. This is used to
116
-     * create xCard or xCal documents.
117
-     *
118
-     * @param Xml\Writer $writer  XML writer.
119
-     *
120
-     * @return void
121
-     */
122
-    protected function xmlSerializeValue(Xml\Writer $writer) {
123
-
124
-        // Special-casing the GEO property.
125
-        //
126
-        // See:
127
-        // http://tools.ietf.org/html/rfc6321#section-3.4.1.2
128
-        if ($this->name === 'GEO') {
129
-
130
-            $value = array_map('floatval', $this->getParts());
131
-
132
-            $writer->writeElement('latitude', $value[0]);
133
-            $writer->writeElement('longitude', $value[1]);
134
-
135
-        }
136
-        else {
137
-            parent::xmlSerializeValue($writer);
138
-        }
139
-
140
-    }
20
+	/**
21
+	 * In case this is a multi-value property. This string will be used as a
22
+	 * delimiter.
23
+	 *
24
+	 * @var string|null
25
+	 */
26
+	public $delimiter = ';';
27
+
28
+	/**
29
+	 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
30
+	 *
31
+	 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
32
+	 * not yet done, but parameters are not included.
33
+	 *
34
+	 * @param string $val
35
+	 *
36
+	 * @return void
37
+	 */
38
+	public function setRawMimeDirValue($val) {
39
+
40
+		$val = explode($this->delimiter, $val);
41
+		foreach ($val as &$item) {
42
+			$item = (float)$item;
43
+		}
44
+		$this->setParts($val);
45
+
46
+	}
47
+
48
+	/**
49
+	 * Returns a raw mime-dir representation of the value.
50
+	 *
51
+	 * @return string
52
+	 */
53
+	public function getRawMimeDirValue() {
54
+
55
+		return implode(
56
+			$this->delimiter,
57
+			$this->getParts()
58
+		);
59
+
60
+	}
61
+
62
+	/**
63
+	 * Returns the type of value.
64
+	 *
65
+	 * This corresponds to the VALUE= parameter. Every property also has a
66
+	 * 'default' valueType.
67
+	 *
68
+	 * @return string
69
+	 */
70
+	public function getValueType() {
71
+
72
+		return 'FLOAT';
73
+
74
+	}
75
+
76
+	/**
77
+	 * Returns the value, in the format it should be encoded for JSON.
78
+	 *
79
+	 * This method must always return an array.
80
+	 *
81
+	 * @return array
82
+	 */
83
+	public function getJsonValue() {
84
+
85
+		$val = array_map('floatval', $this->getParts());
86
+
87
+		// Special-casing the GEO property.
88
+		//
89
+		// See:
90
+		// http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
91
+		if ($this->name === 'GEO') {
92
+			return [$val];
93
+		}
94
+
95
+		return $val;
96
+
97
+	}
98
+
99
+	/**
100
+	 * Hydrate data from a XML subtree, as it would appear in a xCard or xCal
101
+	 * object.
102
+	 *
103
+	 * @param array $value
104
+	 *
105
+	 * @return void
106
+	 */
107
+	public function setXmlValue(array $value) {
108
+
109
+		$value = array_map('floatval', $value);
110
+		parent::setXmlValue($value);
111
+
112
+	}
113
+
114
+	/**
115
+	 * This method serializes only the value of a property. This is used to
116
+	 * create xCard or xCal documents.
117
+	 *
118
+	 * @param Xml\Writer $writer  XML writer.
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function xmlSerializeValue(Xml\Writer $writer) {
123
+
124
+		// Special-casing the GEO property.
125
+		//
126
+		// See:
127
+		// http://tools.ietf.org/html/rfc6321#section-3.4.1.2
128
+		if ($this->name === 'GEO') {
129
+
130
+			$value = array_map('floatval', $this->getParts());
131
+
132
+			$writer->writeElement('latitude', $value[0]);
133
+			$writer->writeElement('longitude', $value[1]);
134
+
135
+		}
136
+		else {
137
+			parent::xmlSerializeValue($writer);
138
+		}
139
+
140
+	}
141 141
 
142 142
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/UtcOffset.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,65 +13,65 @@
 block discarded – undo
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|null
21
-     */
22
-    public $delimiter = null;
16
+	/**
17
+	 * In case this is a multi-value property. This string will be used as a
18
+	 * delimiter.
19
+	 *
20
+	 * @var string|null
21
+	 */
22
+	public $delimiter = null;
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() {
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 33
 
34
-        return 'UTC-OFFSET';
34
+		return 'UTC-OFFSET';
35 35
 
36
-    }
36
+	}
37 37
 
38
-    /**
39
-     * Sets the JSON value, as it would appear in a jCard or jCal object.
40
-     *
41
-     * The value must always be an array.
42
-     *
43
-     * @param array $value
44
-     *
45
-     * @return void
46
-     */
47
-    public function setJsonValue(array $value) {
38
+	/**
39
+	 * Sets the JSON value, as it would appear in a jCard or jCal object.
40
+	 *
41
+	 * The value must always be an array.
42
+	 *
43
+	 * @param array $value
44
+	 *
45
+	 * @return void
46
+	 */
47
+	public function setJsonValue(array $value) {
48 48
 
49
-        $value = array_map(
50
-            public function($value) {
51
-                return str_replace(':', '', $value);
52
-            },
53
-            $value
54
-        );
55
-        parent::setJsonValue($value);
49
+		$value = array_map(
50
+			public function($value) {
51
+				return str_replace(':', '', $value);
52
+			},
53
+			$value
54
+		);
55
+		parent::setJsonValue($value);
56 56
 
57
-    }
57
+	}
58 58
 
59
-    /**
60
-     * Returns the value, in the format it should be encoded for JSON.
61
-     *
62
-     * This method must always return an array.
63
-     *
64
-     * @return array
65
-     */
66
-    public function getJsonValue() {
59
+	/**
60
+	 * Returns the value, in the format it should be encoded for JSON.
61
+	 *
62
+	 * This method must always return an array.
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function getJsonValue() {
67 67
 
68
-        return array_map(
69
-            public function($value) {
70
-                return substr($value, 0, -2) . ':' .
71
-                       substr($value, -2);
72
-            },
73
-            parent::getJsonValue()
74
-        );
68
+		return array_map(
69
+			public function($value) {
70
+				return substr($value, 0, -2) . ':' .
71
+					   substr($value, -2);
72
+			},
73
+			parent::getJsonValue()
74
+		);
75 75
 
76
-    }
76
+	}
77 77
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/Binary.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -20,109 +20,109 @@
 block discarded – undo
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|null
28
-     */
29
-    public $delimiter = null;
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
-     * @return void
39
-     */
40
-    public function setValue($value) {
41
-
42
-        if (is_array($value)) {
43
-
44
-            if (count($value) === 1) {
45
-                $this->value = $value[0];
46
-            } else {
47
-                throw new \InvalidArgumentException('The argument must either be a string or an array with only one child');
48
-            }
49
-
50
-        } else {
51
-
52
-            $this->value = $value;
53
-
54
-        }
55
-
56
-    }
57
-
58
-    /**
59
-     * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
60
-     *
61
-     * This has been 'unfolded', so only 1 line will be passed. Unescaping is
62
-     * not yet done, but parameters are not included.
63
-     *
64
-     * @param string $val
65
-     *
66
-     * @return void
67
-     */
68
-    public function setRawMimeDirValue($val) {
69
-
70
-        $this->value = base64_decode($val);
71
-
72
-    }
73
-
74
-    /**
75
-     * Returns a raw mime-dir representation of the value.
76
-     *
77
-     * @return string
78
-     */
79
-    public function getRawMimeDirValue() {
80
-
81
-        return base64_encode($this->value);
82
-
83
-    }
84
-
85
-    /**
86
-     * Returns the type of value.
87
-     *
88
-     * This corresponds to the VALUE= parameter. Every property also has a
89
-     * 'default' valueType.
90
-     *
91
-     * @return string
92
-     */
93
-    public function getValueType() {
94
-
95
-        return 'BINARY';
96
-
97
-    }
98
-
99
-    /**
100
-     * Returns the value, in the format it should be encoded for json.
101
-     *
102
-     * This method must always return an array.
103
-     *
104
-     * @return array
105
-     */
106
-    public function getJsonValue() {
107
-
108
-        return [base64_encode($this->getValue())];
109
-
110
-    }
111
-
112
-    /**
113
-     * Sets the json value, as it would appear in a jCard or jCal object.
114
-     *
115
-     * The value must always be an array.
116
-     *
117
-     * @param array $value
118
-     *
119
-     * @return void
120
-     */
121
-    public function setJsonValue(array $value) {
122
-
123
-        $value = array_map('base64_decode', $value);
124
-        parent::setJsonValue($value);
125
-
126
-    }
23
+	/**
24
+	 * In case this is a multi-value property. This string will be used as a
25
+	 * delimiter.
26
+	 *
27
+	 * @var string|null
28
+	 */
29
+	public $delimiter = null;
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
+	 * @return void
39
+	 */
40
+	public function setValue($value) {
41
+
42
+		if (is_array($value)) {
43
+
44
+			if (count($value) === 1) {
45
+				$this->value = $value[0];
46
+			} else {
47
+				throw new \InvalidArgumentException('The argument must either be a string or an array with only one child');
48
+			}
49
+
50
+		} else {
51
+
52
+			$this->value = $value;
53
+
54
+		}
55
+
56
+	}
57
+
58
+	/**
59
+	 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
60
+	 *
61
+	 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
62
+	 * not yet done, but parameters are not included.
63
+	 *
64
+	 * @param string $val
65
+	 *
66
+	 * @return void
67
+	 */
68
+	public function setRawMimeDirValue($val) {
69
+
70
+		$this->value = base64_decode($val);
71
+
72
+	}
73
+
74
+	/**
75
+	 * Returns a raw mime-dir representation of the value.
76
+	 *
77
+	 * @return string
78
+	 */
79
+	public function getRawMimeDirValue() {
80
+
81
+		return base64_encode($this->value);
82
+
83
+	}
84
+
85
+	/**
86
+	 * Returns the type of value.
87
+	 *
88
+	 * This corresponds to the VALUE= parameter. Every property also has a
89
+	 * 'default' valueType.
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function getValueType() {
94
+
95
+		return 'BINARY';
96
+
97
+	}
98
+
99
+	/**
100
+	 * Returns the value, in the format it should be encoded for json.
101
+	 *
102
+	 * This method must always return an array.
103
+	 *
104
+	 * @return array
105
+	 */
106
+	public function getJsonValue() {
107
+
108
+		return [base64_encode($this->getValue())];
109
+
110
+	}
111
+
112
+	/**
113
+	 * Sets the json value, as it would appear in a jCard or jCal object.
114
+	 *
115
+	 * The value must always be an array.
116
+	 *
117
+	 * @param array $value
118
+	 *
119
+	 * @return void
120
+	 */
121
+	public function setJsonValue(array $value) {
122
+
123
+		$value = array_map('base64_decode', $value);
124
+		parent::setJsonValue($value);
125
+
126
+	}
127 127
 
128 128
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/FlatText.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,27 +24,27 @@
 block discarded – undo
24 24
  */
25 25
 class FlatText extends Text {
26 26
 
27
-    /**
28
-     * Field separator.
29
-     *
30
-     * @var string
31
-     */
32
-    public $delimiter = ',';
27
+	/**
28
+	 * Field separator.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	public $delimiter = ',';
33 33
 
34
-    /**
35
-     * Sets the value as a quoted-printable encoded string.
36
-     *
37
-     * Overriding this so we're not splitting on a ; delimiter.
38
-     *
39
-     * @param string $val
40
-     *
41
-     * @return void
42
-     */
43
-    public function setQuotedPrintableValue($val) {
34
+	/**
35
+	 * Sets the value as a quoted-printable encoded string.
36
+	 *
37
+	 * Overriding this so we're not splitting on a ; delimiter.
38
+	 *
39
+	 * @param string $val
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function setQuotedPrintableValue($val) {
44 44
 
45
-        $val = quoted_printable_decode($val);
46
-        $this->setValue($val);
45
+		$val = quoted_printable_decode($val);
46
+		$this->setValue($val);
47 47
 
48
-    }
48
+	}
49 49
 
50 50
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/Text.php 1 patch
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -19,395 +19,395 @@
 block discarded – undo
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
-     * @return void
74
-     */
75
-    public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) {
76
-
77
-        // There's two types of multi-valued text properties:
78
-        // 1. multivalue properties.
79
-        // 2. structured value properties
80
-        //
81
-        // The former is always separated by a comma, the latter by semi-colon.
82
-        if (in_array($name, $this->structuredValues)) {
83
-            $this->delimiter = ';';
84
-        }
85
-
86
-        parent::__construct($root, $name, $value, $parameters, $group);
87
-
88
-    }
89
-
90
-    /**
91
-     * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
92
-     *
93
-     * This has been 'unfolded', so only 1 line will be passed. Unescaping is
94
-     * not yet done, but parameters are not included.
95
-     *
96
-     * @param string $val
97
-     *
98
-     * @return void
99
-     */
100
-    public function setRawMimeDirValue($val) {
101
-
102
-        $this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
103
-
104
-    }
105
-
106
-    /**
107
-     * Sets the value as a quoted-printable encoded string.
108
-     *
109
-     * @param string $val
110
-     *
111
-     * @return void
112
-     */
113
-    public function setQuotedPrintableValue($val) {
114
-
115
-        $val = quoted_printable_decode($val);
116
-
117
-        // Quoted printable only appears in vCard 2.1, and the only character
118
-        // that may be escaped there is ;. So we are simply splitting on just
119
-        // that.
120
-        //
121
-        // We also don't have to unescape \\, so all we need to look for is a ;
122
-        // that's not preceeded with a \.
123
-        $regex = '# (?<!\\\\) ; #x';
124
-        $matches = preg_split($regex, $val);
125
-        $this->setValue($matches);
126
-
127
-    }
128
-
129
-    /**
130
-     * Returns a raw mime-dir representation of the value.
131
-     *
132
-     * @return string
133
-     */
134
-    public function getRawMimeDirValue() {
135
-
136
-        $val = $this->getParts();
137
-
138
-        if (isset($this->minimumPropertyValues[$this->name])) {
139
-            $val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
140
-        }
141
-
142
-        foreach ($val as &$item) {
143
-
144
-            if (!is_array($item)) {
145
-                $item = [$item];
146
-            }
147
-
148
-            foreach ($item as &$subItem) {
149
-                $subItem = strtr(
150
-                    $subItem,
151
-                    [
152
-                        '\\' => '\\\\',
153
-                        ';'  => '\;',
154
-                        ','  => '\,',
155
-                        "\n" => '\n',
156
-                        "\r" => "",
157
-                    ]
158
-                );
159
-            }
160
-            $item = implode(',', $item);
161
-
162
-        }
163
-
164
-        return implode($this->delimiter, $val);
165
-
166
-    }
167
-
168
-    /**
169
-     * Returns the value, in the format it should be encoded for json.
170
-     *
171
-     * This method must always return an array.
172
-     *
173
-     * @return array
174
-     */
175
-    public function getJsonValue() {
176
-
177
-        // Structured text values should always be returned as a single
178
-        // array-item. Multi-value text should be returned as multiple items in
179
-        // the top-array.
180
-        if (in_array($this->name, $this->structuredValues)) {
181
-            return [$this->getParts()];
182
-        }
183
-        return $this->getParts();
184
-
185
-    }
186
-
187
-    /**
188
-     * Returns the type of value.
189
-     *
190
-     * This corresponds to the VALUE= parameter. Every property also has a
191
-     * 'default' valueType.
192
-     *
193
-     * @return string
194
-     */
195
-    public function getValueType() {
196
-
197
-        return 'TEXT';
198
-
199
-    }
200
-
201
-    /**
202
-     * Turns the object back into a serialized blob.
203
-     *
204
-     * @return string
205
-     */
206
-    public function serialize() {
207
-
208
-        // We need to kick in a special type of encoding, if it's a 2.1 vcard.
209
-        if ($this->root->getDocumentType() !== Document::VCARD21) {
210
-            return parent::serialize();
211
-        }
212
-
213
-        $val = $this->getParts();
214
-
215
-        if (isset($this->minimumPropertyValues[$this->name])) {
216
-            $val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
217
-        }
218
-
219
-        // Imploding multiple parts into a single value, and splitting the
220
-        // values with ;.
221
-        if (count($val) > 1) {
222
-            foreach ($val as $k => $v) {
223
-                $val[$k] = str_replace(';', '\;', $v);
224
-            }
225
-            $val = implode(';', $val);
226
-        } else {
227
-            $val = $val[0];
228
-        }
229
-
230
-        $str = $this->name;
231
-        if ($this->group) $str = $this->group . '.' . $this->name;
232
-        foreach ($this->parameters as $param) {
233
-
234
-            if ($param->getValue() === 'QUOTED-PRINTABLE') {
235
-                continue;
236
-            }
237
-            $str .= ';' . $param->serialize();
238
-
239
-        }
240
-
241
-
242
-
243
-        // If the resulting value contains a \n, we must encode it as
244
-        // quoted-printable.
245
-        if (strpos($val, "\n") !== false) {
246
-
247
-            $str .= ';ENCODING=QUOTED-PRINTABLE:';
248
-            $lastLine = $str;
249
-            $out = null;
250
-
251
-            // The PHP built-in quoted-printable-encode does not correctly
252
-            // encode newlines for us. Specifically, the \r\n sequence must in
253
-            // vcards be encoded as =0D=OA and we must insert soft-newlines
254
-            // every 75 bytes.
255
-            for ($ii = 0;$ii < strlen($val);$ii++) {
256
-                $ord = ord($val[$ii]);
257
-                // These characters are encoded as themselves.
258
-                if ($ord >= 32 && $ord <= 126) {
259
-                    $lastLine .= $val[$ii];
260
-                } else {
261
-                    $lastLine .= '=' . strtoupper(bin2hex($val[$ii]));
262
-                }
263
-                if (strlen($lastLine) >= 75) {
264
-                    // Soft line break
265
-                    $out .= $lastLine . "=\r\n ";
266
-                    $lastLine = null;
267
-                }
268
-
269
-            }
270
-            if (!is_null($lastLine)) $out .= $lastLine . "\r\n";
271
-            return $out;
272
-
273
-        } else {
274
-            $str .= ':' . $val;
275
-            $out = '';
276
-            while (strlen($str) > 0) {
277
-                if (strlen($str) > 75) {
278
-                    $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
279
-                    $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
280
-                } else {
281
-                    $out .= $str . "\r\n";
282
-                    $str = '';
283
-                    break;
284
-                }
285
-            }
286
-
287
-            return $out;
288
-
289
-        }
290
-
291
-    }
292
-
293
-    /**
294
-     * This method serializes only the value of a property. This is used to
295
-     * create xCard or xCal documents.
296
-     *
297
-     * @param Xml\Writer $writer  XML writer.
298
-     *
299
-     * @return void
300
-     */
301
-    protected function xmlSerializeValue(Xml\Writer $writer) {
302
-
303
-        $values = $this->getParts();
304
-
305
-        $map = function($items) use ($values, $writer) {
306
-            foreach ($items as $i => $item) {
307
-                $writer->writeElement(
308
-                    $item,
309
-                    !empty($values[$i]) ? $values[$i] : null
310
-                );
311
-            }
312
-        };
313
-
314
-        switch ($this->name) {
315
-
316
-            // Special-casing the REQUEST-STATUS property.
317
-            //
318
-            // See:
319
-            // http://tools.ietf.org/html/rfc6321#section-3.4.1.3
320
-            case 'REQUEST-STATUS':
321
-                $writer->writeElement('code', $values[0]);
322
-                $writer->writeElement('description', $values[1]);
323
-
324
-                if (isset($values[2])) {
325
-                    $writer->writeElement('data', $values[2]);
326
-                }
327
-                break;
328
-
329
-            case 'N':
330
-                $map([
331
-                    'surname',
332
-                    'given',
333
-                    'additional',
334
-                    'prefix',
335
-                    'suffix'
336
-                ]);
337
-                break;
338
-
339
-            case 'GENDER':
340
-                $map([
341
-                    'sex',
342
-                    'text'
343
-                ]);
344
-                break;
345
-
346
-            case 'ADR':
347
-                $map([
348
-                    'pobox',
349
-                    'ext',
350
-                    'street',
351
-                    'locality',
352
-                    'region',
353
-                    'code',
354
-                    'country'
355
-                ]);
356
-                break;
357
-
358
-            case 'CLIENTPIDMAP':
359
-                $map([
360
-                    'sourceid',
361
-                    'uri'
362
-                ]);
363
-                break;
364
-
365
-            default:
366
-                parent::xmlSerializeValue($writer);
367
-        }
368
-
369
-    }
370
-
371
-    /**
372
-     * Validates the node for correctness.
373
-     *
374
-     * The following options are supported:
375
-     *   - Node::REPAIR - If something is broken, and automatic repair may
376
-     *                    be attempted.
377
-     *
378
-     * An array is returned with warnings.
379
-     *
380
-     * Every item in the array has the following properties:
381
-     *    * level - (number between 1 and 3 with severity information)
382
-     *    * message - (human readable message)
383
-     *    * node - (reference to the offending node)
384
-     *
385
-     * @param int $options
386
-     *
387
-     * @return array
388
-     */
389
-    public function validate($options = 0) {
390
-
391
-        $warnings = parent::validate($options);
392
-
393
-        if (isset($this->minimumPropertyValues[$this->name])) {
394
-
395
-            $minimum = $this->minimumPropertyValues[$this->name];
396
-            $parts = $this->getParts();
397
-            if (count($parts) < $minimum) {
398
-                $warnings[] = [
399
-                    'level'   => $options & self::REPAIR ? 1 : 3,
400
-                    'message' => 'The ' . $this->name  . ' property must have at least ' . $minimum . ' values. It only has ' . count($parts),
401
-                    'node'    => $this,
402
-                ];
403
-                if ($options & self::REPAIR) {
404
-                    $parts = array_pad($parts, $minimum, '');
405
-                    $this->setParts($parts);
406
-                }
407
-            }
408
-
409
-        }
410
-        return $warnings;
411
-
412
-    }
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
+	 * @return void
74
+	 */
75
+	public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) {
76
+
77
+		// There's two types of multi-valued text properties:
78
+		// 1. multivalue properties.
79
+		// 2. structured value properties
80
+		//
81
+		// The former is always separated by a comma, the latter by semi-colon.
82
+		if (in_array($name, $this->structuredValues)) {
83
+			$this->delimiter = ';';
84
+		}
85
+
86
+		parent::__construct($root, $name, $value, $parameters, $group);
87
+
88
+	}
89
+
90
+	/**
91
+	 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
92
+	 *
93
+	 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
94
+	 * not yet done, but parameters are not included.
95
+	 *
96
+	 * @param string $val
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function setRawMimeDirValue($val) {
101
+
102
+		$this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
103
+
104
+	}
105
+
106
+	/**
107
+	 * Sets the value as a quoted-printable encoded string.
108
+	 *
109
+	 * @param string $val
110
+	 *
111
+	 * @return void
112
+	 */
113
+	public function setQuotedPrintableValue($val) {
114
+
115
+		$val = quoted_printable_decode($val);
116
+
117
+		// Quoted printable only appears in vCard 2.1, and the only character
118
+		// that may be escaped there is ;. So we are simply splitting on just
119
+		// that.
120
+		//
121
+		// We also don't have to unescape \\, so all we need to look for is a ;
122
+		// that's not preceeded with a \.
123
+		$regex = '# (?<!\\\\) ; #x';
124
+		$matches = preg_split($regex, $val);
125
+		$this->setValue($matches);
126
+
127
+	}
128
+
129
+	/**
130
+	 * Returns a raw mime-dir representation of the value.
131
+	 *
132
+	 * @return string
133
+	 */
134
+	public function getRawMimeDirValue() {
135
+
136
+		$val = $this->getParts();
137
+
138
+		if (isset($this->minimumPropertyValues[$this->name])) {
139
+			$val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
140
+		}
141
+
142
+		foreach ($val as &$item) {
143
+
144
+			if (!is_array($item)) {
145
+				$item = [$item];
146
+			}
147
+
148
+			foreach ($item as &$subItem) {
149
+				$subItem = strtr(
150
+					$subItem,
151
+					[
152
+						'\\' => '\\\\',
153
+						';'  => '\;',
154
+						','  => '\,',
155
+						"\n" => '\n',
156
+						"\r" => "",
157
+					]
158
+				);
159
+			}
160
+			$item = implode(',', $item);
161
+
162
+		}
163
+
164
+		return implode($this->delimiter, $val);
165
+
166
+	}
167
+
168
+	/**
169
+	 * Returns the value, in the format it should be encoded for json.
170
+	 *
171
+	 * This method must always return an array.
172
+	 *
173
+	 * @return array
174
+	 */
175
+	public function getJsonValue() {
176
+
177
+		// Structured text values should always be returned as a single
178
+		// array-item. Multi-value text should be returned as multiple items in
179
+		// the top-array.
180
+		if (in_array($this->name, $this->structuredValues)) {
181
+			return [$this->getParts()];
182
+		}
183
+		return $this->getParts();
184
+
185
+	}
186
+
187
+	/**
188
+	 * Returns the type of value.
189
+	 *
190
+	 * This corresponds to the VALUE= parameter. Every property also has a
191
+	 * 'default' valueType.
192
+	 *
193
+	 * @return string
194
+	 */
195
+	public function getValueType() {
196
+
197
+		return 'TEXT';
198
+
199
+	}
200
+
201
+	/**
202
+	 * Turns the object back into a serialized blob.
203
+	 *
204
+	 * @return string
205
+	 */
206
+	public function serialize() {
207
+
208
+		// We need to kick in a special type of encoding, if it's a 2.1 vcard.
209
+		if ($this->root->getDocumentType() !== Document::VCARD21) {
210
+			return parent::serialize();
211
+		}
212
+
213
+		$val = $this->getParts();
214
+
215
+		if (isset($this->minimumPropertyValues[$this->name])) {
216
+			$val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
217
+		}
218
+
219
+		// Imploding multiple parts into a single value, and splitting the
220
+		// values with ;.
221
+		if (count($val) > 1) {
222
+			foreach ($val as $k => $v) {
223
+				$val[$k] = str_replace(';', '\;', $v);
224
+			}
225
+			$val = implode(';', $val);
226
+		} else {
227
+			$val = $val[0];
228
+		}
229
+
230
+		$str = $this->name;
231
+		if ($this->group) $str = $this->group . '.' . $this->name;
232
+		foreach ($this->parameters as $param) {
233
+
234
+			if ($param->getValue() === 'QUOTED-PRINTABLE') {
235
+				continue;
236
+			}
237
+			$str .= ';' . $param->serialize();
238
+
239
+		}
240
+
241
+
242
+
243
+		// If the resulting value contains a \n, we must encode it as
244
+		// quoted-printable.
245
+		if (strpos($val, "\n") !== false) {
246
+
247
+			$str .= ';ENCODING=QUOTED-PRINTABLE:';
248
+			$lastLine = $str;
249
+			$out = null;
250
+
251
+			// The PHP built-in quoted-printable-encode does not correctly
252
+			// encode newlines for us. Specifically, the \r\n sequence must in
253
+			// vcards be encoded as =0D=OA and we must insert soft-newlines
254
+			// every 75 bytes.
255
+			for ($ii = 0;$ii < strlen($val);$ii++) {
256
+				$ord = ord($val[$ii]);
257
+				// These characters are encoded as themselves.
258
+				if ($ord >= 32 && $ord <= 126) {
259
+					$lastLine .= $val[$ii];
260
+				} else {
261
+					$lastLine .= '=' . strtoupper(bin2hex($val[$ii]));
262
+				}
263
+				if (strlen($lastLine) >= 75) {
264
+					// Soft line break
265
+					$out .= $lastLine . "=\r\n ";
266
+					$lastLine = null;
267
+				}
268
+
269
+			}
270
+			if (!is_null($lastLine)) $out .= $lastLine . "\r\n";
271
+			return $out;
272
+
273
+		} else {
274
+			$str .= ':' . $val;
275
+			$out = '';
276
+			while (strlen($str) > 0) {
277
+				if (strlen($str) > 75) {
278
+					$out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
279
+					$str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
280
+				} else {
281
+					$out .= $str . "\r\n";
282
+					$str = '';
283
+					break;
284
+				}
285
+			}
286
+
287
+			return $out;
288
+
289
+		}
290
+
291
+	}
292
+
293
+	/**
294
+	 * This method serializes only the value of a property. This is used to
295
+	 * create xCard or xCal documents.
296
+	 *
297
+	 * @param Xml\Writer $writer  XML writer.
298
+	 *
299
+	 * @return void
300
+	 */
301
+	protected function xmlSerializeValue(Xml\Writer $writer) {
302
+
303
+		$values = $this->getParts();
304
+
305
+		$map = function($items) use ($values, $writer) {
306
+			foreach ($items as $i => $item) {
307
+				$writer->writeElement(
308
+					$item,
309
+					!empty($values[$i]) ? $values[$i] : null
310
+				);
311
+			}
312
+		};
313
+
314
+		switch ($this->name) {
315
+
316
+			// Special-casing the REQUEST-STATUS property.
317
+			//
318
+			// See:
319
+			// http://tools.ietf.org/html/rfc6321#section-3.4.1.3
320
+			case 'REQUEST-STATUS':
321
+				$writer->writeElement('code', $values[0]);
322
+				$writer->writeElement('description', $values[1]);
323
+
324
+				if (isset($values[2])) {
325
+					$writer->writeElement('data', $values[2]);
326
+				}
327
+				break;
328
+
329
+			case 'N':
330
+				$map([
331
+					'surname',
332
+					'given',
333
+					'additional',
334
+					'prefix',
335
+					'suffix'
336
+				]);
337
+				break;
338
+
339
+			case 'GENDER':
340
+				$map([
341
+					'sex',
342
+					'text'
343
+				]);
344
+				break;
345
+
346
+			case 'ADR':
347
+				$map([
348
+					'pobox',
349
+					'ext',
350
+					'street',
351
+					'locality',
352
+					'region',
353
+					'code',
354
+					'country'
355
+				]);
356
+				break;
357
+
358
+			case 'CLIENTPIDMAP':
359
+				$map([
360
+					'sourceid',
361
+					'uri'
362
+				]);
363
+				break;
364
+
365
+			default:
366
+				parent::xmlSerializeValue($writer);
367
+		}
368
+
369
+	}
370
+
371
+	/**
372
+	 * Validates the node for correctness.
373
+	 *
374
+	 * The following options are supported:
375
+	 *   - Node::REPAIR - If something is broken, and automatic repair may
376
+	 *                    be attempted.
377
+	 *
378
+	 * An array is returned with warnings.
379
+	 *
380
+	 * Every item in the array has the following properties:
381
+	 *    * level - (number between 1 and 3 with severity information)
382
+	 *    * message - (human readable message)
383
+	 *    * node - (reference to the offending node)
384
+	 *
385
+	 * @param int $options
386
+	 *
387
+	 * @return array
388
+	 */
389
+	public function validate($options = 0) {
390
+
391
+		$warnings = parent::validate($options);
392
+
393
+		if (isset($this->minimumPropertyValues[$this->name])) {
394
+
395
+			$minimum = $this->minimumPropertyValues[$this->name];
396
+			$parts = $this->getParts();
397
+			if (count($parts) < $minimum) {
398
+				$warnings[] = [
399
+					'level'   => $options & self::REPAIR ? 1 : 3,
400
+					'message' => 'The ' . $this->name  . ' property must have at least ' . $minimum . ' values. It only has ' . count($parts),
401
+					'node'    => $this,
402
+				];
403
+				if ($options & self::REPAIR) {
404
+					$parts = array_pad($parts, $minimum, '');
405
+					$this->setParts($parts);
406
+				}
407
+			}
408
+
409
+		}
410
+		return $warnings;
411
+
412
+	}
413 413
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/VCard/TimeStamp.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
  */
18 18
 class TimeStamp extends Text {
19 19
 
20
-    /**
21
-     * In case this is a multi-value property. This string will be used as a
22
-     * delimiter.
23
-     *
24
-     * @var string|null
25
-     */
26
-    public $delimiter = null;
27
-
28
-    /**
29
-     * Returns the type of value.
30
-     *
31
-     * This corresponds to the VALUE= parameter. Every property also has a
32
-     * 'default' valueType.
33
-     *
34
-     * @return string
35
-     */
36
-    public function getValueType() {
37
-
38
-        return 'TIMESTAMP';
39
-
40
-    }
41
-
42
-    /**
43
-     * Returns the value, in the format it should be encoded for json.
44
-     *
45
-     * This method must always return an array.
46
-     *
47
-     * @return array
48
-     */
49
-    public function getJsonValue() {
50
-
51
-        $parts = DateTimeParser::parseVCardDateTime($this->getValue());
52
-
53
-        $dateStr =
54
-            $parts['year'] . '-' .
55
-            $parts['month'] . '-' .
56
-            $parts['date'] . 'T' .
57
-            $parts['hour'] . ':' .
58
-            $parts['minute'] . ':' .
59
-            $parts['second'];
60
-
61
-        // Timezone
62
-        if (!is_null($parts['timezone'])) {
63
-            $dateStr .= $parts['timezone'];
64
-        }
65
-
66
-        return [$dateStr];
67
-
68
-    }
69
-
70
-    /**
71
-     * This method serializes only the value of a property. This is used to
72
-     * create xCard or xCal documents.
73
-     *
74
-     * @param Xml\Writer $writer  XML writer.
75
-     *
76
-     * @return void
77
-     */
78
-    protected function xmlSerializeValue(Xml\Writer $writer) {
79
-
80
-        // xCard is the only XML and JSON format that has the same date and time
81
-        // format than vCard.
82
-        $valueType = strtolower($this->getValueType());
83
-        $writer->writeElement($valueType, $this->getValue());
84
-
85
-    }
20
+	/**
21
+	 * In case this is a multi-value property. This string will be used as a
22
+	 * delimiter.
23
+	 *
24
+	 * @var string|null
25
+	 */
26
+	public $delimiter = null;
27
+
28
+	/**
29
+	 * Returns the type of value.
30
+	 *
31
+	 * This corresponds to the VALUE= parameter. Every property also has a
32
+	 * 'default' valueType.
33
+	 *
34
+	 * @return string
35
+	 */
36
+	public function getValueType() {
37
+
38
+		return 'TIMESTAMP';
39
+
40
+	}
41
+
42
+	/**
43
+	 * Returns the value, in the format it should be encoded for json.
44
+	 *
45
+	 * This method must always return an array.
46
+	 *
47
+	 * @return array
48
+	 */
49
+	public function getJsonValue() {
50
+
51
+		$parts = DateTimeParser::parseVCardDateTime($this->getValue());
52
+
53
+		$dateStr =
54
+			$parts['year'] . '-' .
55
+			$parts['month'] . '-' .
56
+			$parts['date'] . 'T' .
57
+			$parts['hour'] . ':' .
58
+			$parts['minute'] . ':' .
59
+			$parts['second'];
60
+
61
+		// Timezone
62
+		if (!is_null($parts['timezone'])) {
63
+			$dateStr .= $parts['timezone'];
64
+		}
65
+
66
+		return [$dateStr];
67
+
68
+	}
69
+
70
+	/**
71
+	 * This method serializes only the value of a property. This is used to
72
+	 * create xCard or xCal documents.
73
+	 *
74
+	 * @param Xml\Writer $writer  XML writer.
75
+	 *
76
+	 * @return void
77
+	 */
78
+	protected function xmlSerializeValue(Xml\Writer $writer) {
79
+
80
+		// xCard is the only XML and JSON format that has the same date and time
81
+		// format than vCard.
82
+		$valueType = strtolower($this->getValueType());
83
+		$writer->writeElement($valueType, $this->getValue());
84
+
85
+	}
86 86
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/VCard/LanguageTag.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace Sabre\VObject\Property\VCard;
4 4
 
5 5
 use
6
-    Sabre\VObject\Property;
6
+	Sabre\VObject\Property;
7 7
 
8 8
 /**
9 9
  * LanguageTag property.
@@ -16,45 +16,45 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class LanguageTag 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
-     * @return void
28
-     */
29
-    public function setRawMimeDirValue($val) {
30
-
31
-        $this->setValue($val);
32
-
33
-    }
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->getValue();
43
-
44
-    }
45
-
46
-    /**
47
-     * Returns the type of value.
48
-     *
49
-     * This corresponds to the VALUE= parameter. Every property also has a
50
-     * 'default' valueType.
51
-     *
52
-     * @return string
53
-     */
54
-    public function getValueType() {
55
-
56
-        return 'LANGUAGE-TAG';
57
-
58
-    }
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
+	 * @return void
28
+	 */
29
+	public function setRawMimeDirValue($val) {
30
+
31
+		$this->setValue($val);
32
+
33
+	}
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->getValue();
43
+
44
+	}
45
+
46
+	/**
47
+	 * Returns the type of value.
48
+	 *
49
+	 * This corresponds to the VALUE= parameter. Every property also has a
50
+	 * 'default' valueType.
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public function getValueType() {
55
+
56
+		return 'LANGUAGE-TAG';
57
+
58
+	}
59 59
 
60 60
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/VObject/Property/VCard/DateAndOrTime.php 1 patch
Indentation   +379 added lines, -379 removed lines patch added patch discarded remove patch
@@ -21,383 +21,383 @@
 block discarded – undo
21 21
  */
22 22
 class DateAndOrTime extends Property {
23 23
 
24
-    /**
25
-     * Field separator.
26
-     *
27
-     * @var null|string
28
-     */
29
-    public $delimiter = null;
30
-
31
-    /**
32
-     * Returns the type of value.
33
-     *
34
-     * This corresponds to the VALUE= parameter. Every property also has a
35
-     * 'default' valueType.
36
-     *
37
-     * @return string
38
-     */
39
-    public function getValueType() {
40
-
41
-        return 'DATE-AND-OR-TIME';
42
-
43
-    }
44
-
45
-    /**
46
-     * Sets a multi-valued property.
47
-     *
48
-     * You may also specify DateTime objects here.
49
-     *
50
-     * @param array $parts
51
-     *
52
-     * @return void
53
-     */
54
-    public function setParts(array $parts) {
55
-
56
-        if (count($parts) > 1) {
57
-            throw new \InvalidArgumentException('Only one value allowed');
58
-        }
59
-        if (isset($parts[0]) && $parts[0] instanceof \DateTime) {
60
-            $this->setDateTime($parts[0]);
61
-        } else {
62
-            parent::setParts($parts);
63
-        }
64
-
65
-    }
66
-
67
-    /**
68
-     * Updates the current value.
69
-     *
70
-     * This may be either a single, or multiple strings in an array.
71
-     *
72
-     * Instead of strings, you may also use DateTime here.
73
-     *
74
-     * @param string|array|\DateTime $value
75
-     *
76
-     * @return void
77
-     */
78
-    public function setValue($value) {
79
-
80
-        if ($value instanceof \DateTime) {
81
-            $this->setDateTime($value);
82
-        } else {
83
-            parent::setValue($value);
84
-        }
85
-
86
-    }
87
-
88
-    /**
89
-     * Sets the property as a DateTime object.
90
-     *
91
-     * @param DateTimeInterface $dt
92
-     *
93
-     * @return void
94
-     */
95
-    public function setDateTime(DateTimeInterface $dt) {
96
-
97
-        $tz = $dt->getTimeZone();
98
-        $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']);
99
-
100
-        if ($isUtc) {
101
-            $value = $dt->format('Ymd\\THis\\Z');
102
-        } else {
103
-            // Calculating the offset.
104
-            $value = $dt->format('Ymd\\THisO');
105
-        }
106
-
107
-        $this->value = $value;
108
-
109
-    }
110
-
111
-    /**
112
-     * Returns a date-time value.
113
-     *
114
-     * Note that if this property contained more than 1 date-time, only the
115
-     * first will be returned. To get an array with multiple values, call
116
-     * getDateTimes.
117
-     *
118
-     * If no time was specified, we will always use midnight (in the default
119
-     * timezone) as the time.
120
-     *
121
-     * If parts of the date were omitted, such as the year, we will grab the
122
-     * current values for those. So at the time of writing, if the year was
123
-     * omitted, we would have filled in 2014.
124
-     *
125
-     * @return DateTimeImmutable
126
-     */
127
-    public function getDateTime() {
128
-
129
-        $now = new DateTime();
130
-
131
-        $tzFormat = $now->getTimezone()->getOffset($now) === 0 ? '\\Z' : 'O';
132
-        $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' . $tzFormat));
133
-
134
-        $dateParts = DateTimeParser::parseVCardDateTime($this->getValue());
135
-
136
-        // This sets all the missing parts to the current date/time.
137
-        // So if the year was missing for a birthday, we're making it 'this
138
-        // year'.
139
-        foreach ($dateParts as $k => $v) {
140
-            if (is_null($v)) {
141
-                $dateParts[$k] = $nowParts[$k];
142
-            }
143
-        }
144
-        return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]");
145
-
146
-    }
147
-
148
-    /**
149
-     * Returns the value, in the format it should be encoded for json.
150
-     *
151
-     * This method must always return an array.
152
-     *
153
-     * @return array
154
-     */
155
-    public function getJsonValue() {
156
-
157
-        $parts = DateTimeParser::parseVCardDateTime($this->getValue());
158
-
159
-        $dateStr = '';
160
-
161
-        // Year
162
-        if (!is_null($parts['year'])) {
163
-
164
-            $dateStr .= $parts['year'];
165
-
166
-            if (!is_null($parts['month'])) {
167
-                // If a year and a month is set, we need to insert a separator
168
-                // dash.
169
-                $dateStr .= '-';
170
-            }
171
-
172
-        } else {
173
-
174
-            if (!is_null($parts['month']) || !is_null($parts['date'])) {
175
-                // Inserting two dashes
176
-                $dateStr .= '--';
177
-            }
178
-
179
-        }
180
-
181
-        // Month
182
-        if (!is_null($parts['month'])) {
183
-
184
-            $dateStr .= $parts['month'];
185
-
186
-            if (isset($parts['date'])) {
187
-                // If month and date are set, we need the separator dash.
188
-                $dateStr .= '-';
189
-            }
190
-
191
-        } elseif (isset($parts['date'])) {
192
-            // If the month is empty, and a date is set, we need a 'empty
193
-            // dash'
194
-            $dateStr .= '-';
195
-        }
196
-
197
-        // Date
198
-        if (!is_null($parts['date'])) {
199
-            $dateStr .= $parts['date'];
200
-        }
201
-
202
-
203
-        // Early exit if we don't have a time string.
204
-        if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) {
205
-            return [$dateStr];
206
-        }
207
-
208
-        $dateStr .= 'T';
209
-
210
-        // Hour
211
-        if (!is_null($parts['hour'])) {
212
-
213
-            $dateStr .= $parts['hour'];
214
-
215
-            if (!is_null($parts['minute'])) {
216
-                $dateStr .= ':';
217
-            }
218
-
219
-        } else {
220
-            // We know either minute or second _must_ be set, so we insert a
221
-            // dash for an empty value.
222
-            $dateStr .= '-';
223
-        }
224
-
225
-        // Minute
226
-        if (!is_null($parts['minute'])) {
227
-
228
-            $dateStr .= $parts['minute'];
229
-
230
-            if (!is_null($parts['second'])) {
231
-                $dateStr .= ':';
232
-            }
233
-
234
-        } elseif (isset($parts['second'])) {
235
-            // Dash for empty minute
236
-            $dateStr .= '-';
237
-        }
238
-
239
-        // Second
240
-        if (!is_null($parts['second'])) {
241
-            $dateStr .= $parts['second'];
242
-        }
243
-
244
-        // Timezone
245
-        if (!is_null($parts['timezone'])) {
246
-            $dateStr .= $parts['timezone'];
247
-        }
248
-
249
-        return [$dateStr];
250
-
251
-    }
252
-
253
-    /**
254
-     * This method serializes only the value of a property. This is used to
255
-     * create xCard or xCal documents.
256
-     *
257
-     * @param Xml\Writer $writer  XML writer.
258
-     *
259
-     * @return void
260
-     */
261
-    protected function xmlSerializeValue(Xml\Writer $writer) {
262
-
263
-        $valueType = strtolower($this->getValueType());
264
-        $parts     = DateTimeParser::parseVCardDateAndOrTime($this->getValue());
265
-        $value     = '';
266
-
267
-        $d = function($part) use ($parts) {
268
-            return !is_null($parts[$part]);
269
-        };
270
-
271
-        $r = function($part) use ($parts) {
272
-            return $parts[$part];
273
-        };
274
-
275
-        // From the Relax NG Schema.
276
-        //
277
-        // # 4.3.1
278
-        // value-date = element date {
279
-        //     xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" }
280
-        //   }
281
-        if (($d('year') ||  $d('month')  ||  $d('date'))
282
-            && (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) {
283
-
284
-            if ($d('year') && $d('month') && $d('date')) {
285
-                $value .= $r('year') . $r('month') . $r('date');
286
-            } elseif ($d('year') && $d('month') && !$d('date')) {
287
-                $value .= $r('year') . '-' . $r('month');
288
-            } elseif (!$d('year') && $d('month')) {
289
-                $value .= '--' . $r('month') . $r('date');
290
-            } elseif (!$d('year') && !$d('month') && $d('date')) {
291
-                $value .= '---' . $r('date');
292
-            }
293
-
294
-        // # 4.3.2
295
-        // value-time = element time {
296
-        //     xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)"
297
-        //                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
298
-        //   }
299
-        } elseif ((!$d('year') && !$d('month')  && !$d('date'))
300
-                  && ($d('hour') ||  $d('minute') ||  $d('second'))) {
301
-
302
-            if ($d('hour')) {
303
-                $value .= $r('hour') . $r('minute') . $r('second');
304
-            } elseif ($d('minute')) {
305
-                $value .= '-' . $r('minute') . $r('second');
306
-            } elseif ($d('second')) {
307
-                $value .= '--' . $r('second');
308
-            }
309
-
310
-            $value .= $r('timezone');
311
-
312
-        // # 4.3.3
313
-        // value-date-time = element date-time {
314
-        //     xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?"
315
-        //                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
316
-        //   }
317
-        } elseif ($d('date') && $d('hour')) {
318
-
319
-            if ($d('year') && $d('month') && $d('date')) {
320
-                $value .= $r('year') . $r('month') . $r('date');
321
-            } elseif (!$d('year') && $d('month') && $d('date')) {
322
-                $value .= '--' . $r('month') . $r('date');
323
-            } elseif (!$d('year') && !$d('month') && $d('date')) {
324
-                $value .= '---' . $r('date');
325
-            }
326
-
327
-            $value .= 'T' . $r('hour') . $r('minute') . $r('second') .
328
-                      $r('timezone');
329
-
330
-        }
331
-
332
-        $writer->writeElement($valueType, $value);
333
-
334
-    }
335
-
336
-    /**
337
-     * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
338
-     *
339
-     * This has been 'unfolded', so only 1 line will be passed. Unescaping is
340
-     * not yet done, but parameters are not included.
341
-     *
342
-     * @param string $val
343
-     *
344
-     * @return void
345
-     */
346
-    public function setRawMimeDirValue($val) {
347
-
348
-        $this->setValue($val);
349
-
350
-    }
351
-
352
-    /**
353
-     * Returns a raw mime-dir representation of the value.
354
-     *
355
-     * @return string
356
-     */
357
-    public function getRawMimeDirValue() {
358
-
359
-        return implode($this->delimiter, $this->getParts());
360
-
361
-    }
362
-
363
-    /**
364
-     * Validates the node for correctness.
365
-     *
366
-     * The following options are supported:
367
-     *   Node::REPAIR - May attempt to automatically repair the problem.
368
-     *
369
-     * This method returns an array with detected problems.
370
-     * Every element has the following properties:
371
-     *
372
-     *  * level - problem level.
373
-     *  * message - A human-readable string describing the issue.
374
-     *  * node - A reference to the problematic node.
375
-     *
376
-     * The level means:
377
-     *   1 - The issue was repaired (only happens if REPAIR was turned on)
378
-     *   2 - An inconsequential issue
379
-     *   3 - A severe issue.
380
-     *
381
-     * @param int $options
382
-     *
383
-     * @return array
384
-     */
385
-    public function validate($options = 0) {
386
-
387
-        $messages = parent::validate($options);
388
-        $value = $this->getValue();
389
-
390
-        try {
391
-            DateTimeParser::parseVCardDateTime($value);
392
-        } catch (InvalidDataException $e) {
393
-            $messages[] = [
394
-                'level'   => 3,
395
-                'message' => 'The supplied value (' . $value . ') is not a correct DATE-AND-OR-TIME property',
396
-                'node'    => $this,
397
-            ];
398
-        }
399
-
400
-        return $messages;
401
-
402
-    }
24
+	/**
25
+	 * Field separator.
26
+	 *
27
+	 * @var null|string
28
+	 */
29
+	public $delimiter = null;
30
+
31
+	/**
32
+	 * Returns the type of value.
33
+	 *
34
+	 * This corresponds to the VALUE= parameter. Every property also has a
35
+	 * 'default' valueType.
36
+	 *
37
+	 * @return string
38
+	 */
39
+	public function getValueType() {
40
+
41
+		return 'DATE-AND-OR-TIME';
42
+
43
+	}
44
+
45
+	/**
46
+	 * Sets a multi-valued property.
47
+	 *
48
+	 * You may also specify DateTime objects here.
49
+	 *
50
+	 * @param array $parts
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function setParts(array $parts) {
55
+
56
+		if (count($parts) > 1) {
57
+			throw new \InvalidArgumentException('Only one value allowed');
58
+		}
59
+		if (isset($parts[0]) && $parts[0] instanceof \DateTime) {
60
+			$this->setDateTime($parts[0]);
61
+		} else {
62
+			parent::setParts($parts);
63
+		}
64
+
65
+	}
66
+
67
+	/**
68
+	 * Updates the current value.
69
+	 *
70
+	 * This may be either a single, or multiple strings in an array.
71
+	 *
72
+	 * Instead of strings, you may also use DateTime here.
73
+	 *
74
+	 * @param string|array|\DateTime $value
75
+	 *
76
+	 * @return void
77
+	 */
78
+	public function setValue($value) {
79
+
80
+		if ($value instanceof \DateTime) {
81
+			$this->setDateTime($value);
82
+		} else {
83
+			parent::setValue($value);
84
+		}
85
+
86
+	}
87
+
88
+	/**
89
+	 * Sets the property as a DateTime object.
90
+	 *
91
+	 * @param DateTimeInterface $dt
92
+	 *
93
+	 * @return void
94
+	 */
95
+	public function setDateTime(DateTimeInterface $dt) {
96
+
97
+		$tz = $dt->getTimeZone();
98
+		$isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']);
99
+
100
+		if ($isUtc) {
101
+			$value = $dt->format('Ymd\\THis\\Z');
102
+		} else {
103
+			// Calculating the offset.
104
+			$value = $dt->format('Ymd\\THisO');
105
+		}
106
+
107
+		$this->value = $value;
108
+
109
+	}
110
+
111
+	/**
112
+	 * Returns a date-time value.
113
+	 *
114
+	 * Note that if this property contained more than 1 date-time, only the
115
+	 * first will be returned. To get an array with multiple values, call
116
+	 * getDateTimes.
117
+	 *
118
+	 * If no time was specified, we will always use midnight (in the default
119
+	 * timezone) as the time.
120
+	 *
121
+	 * If parts of the date were omitted, such as the year, we will grab the
122
+	 * current values for those. So at the time of writing, if the year was
123
+	 * omitted, we would have filled in 2014.
124
+	 *
125
+	 * @return DateTimeImmutable
126
+	 */
127
+	public function getDateTime() {
128
+
129
+		$now = new DateTime();
130
+
131
+		$tzFormat = $now->getTimezone()->getOffset($now) === 0 ? '\\Z' : 'O';
132
+		$nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' . $tzFormat));
133
+
134
+		$dateParts = DateTimeParser::parseVCardDateTime($this->getValue());
135
+
136
+		// This sets all the missing parts to the current date/time.
137
+		// So if the year was missing for a birthday, we're making it 'this
138
+		// year'.
139
+		foreach ($dateParts as $k => $v) {
140
+			if (is_null($v)) {
141
+				$dateParts[$k] = $nowParts[$k];
142
+			}
143
+		}
144
+		return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]");
145
+
146
+	}
147
+
148
+	/**
149
+	 * Returns the value, in the format it should be encoded for json.
150
+	 *
151
+	 * This method must always return an array.
152
+	 *
153
+	 * @return array
154
+	 */
155
+	public function getJsonValue() {
156
+
157
+		$parts = DateTimeParser::parseVCardDateTime($this->getValue());
158
+
159
+		$dateStr = '';
160
+
161
+		// Year
162
+		if (!is_null($parts['year'])) {
163
+
164
+			$dateStr .= $parts['year'];
165
+
166
+			if (!is_null($parts['month'])) {
167
+				// If a year and a month is set, we need to insert a separator
168
+				// dash.
169
+				$dateStr .= '-';
170
+			}
171
+
172
+		} else {
173
+
174
+			if (!is_null($parts['month']) || !is_null($parts['date'])) {
175
+				// Inserting two dashes
176
+				$dateStr .= '--';
177
+			}
178
+
179
+		}
180
+
181
+		// Month
182
+		if (!is_null($parts['month'])) {
183
+
184
+			$dateStr .= $parts['month'];
185
+
186
+			if (isset($parts['date'])) {
187
+				// If month and date are set, we need the separator dash.
188
+				$dateStr .= '-';
189
+			}
190
+
191
+		} elseif (isset($parts['date'])) {
192
+			// If the month is empty, and a date is set, we need a 'empty
193
+			// dash'
194
+			$dateStr .= '-';
195
+		}
196
+
197
+		// Date
198
+		if (!is_null($parts['date'])) {
199
+			$dateStr .= $parts['date'];
200
+		}
201
+
202
+
203
+		// Early exit if we don't have a time string.
204
+		if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) {
205
+			return [$dateStr];
206
+		}
207
+
208
+		$dateStr .= 'T';
209
+
210
+		// Hour
211
+		if (!is_null($parts['hour'])) {
212
+
213
+			$dateStr .= $parts['hour'];
214
+
215
+			if (!is_null($parts['minute'])) {
216
+				$dateStr .= ':';
217
+			}
218
+
219
+		} else {
220
+			// We know either minute or second _must_ be set, so we insert a
221
+			// dash for an empty value.
222
+			$dateStr .= '-';
223
+		}
224
+
225
+		// Minute
226
+		if (!is_null($parts['minute'])) {
227
+
228
+			$dateStr .= $parts['minute'];
229
+
230
+			if (!is_null($parts['second'])) {
231
+				$dateStr .= ':';
232
+			}
233
+
234
+		} elseif (isset($parts['second'])) {
235
+			// Dash for empty minute
236
+			$dateStr .= '-';
237
+		}
238
+
239
+		// Second
240
+		if (!is_null($parts['second'])) {
241
+			$dateStr .= $parts['second'];
242
+		}
243
+
244
+		// Timezone
245
+		if (!is_null($parts['timezone'])) {
246
+			$dateStr .= $parts['timezone'];
247
+		}
248
+
249
+		return [$dateStr];
250
+
251
+	}
252
+
253
+	/**
254
+	 * This method serializes only the value of a property. This is used to
255
+	 * create xCard or xCal documents.
256
+	 *
257
+	 * @param Xml\Writer $writer  XML writer.
258
+	 *
259
+	 * @return void
260
+	 */
261
+	protected function xmlSerializeValue(Xml\Writer $writer) {
262
+
263
+		$valueType = strtolower($this->getValueType());
264
+		$parts     = DateTimeParser::parseVCardDateAndOrTime($this->getValue());
265
+		$value     = '';
266
+
267
+		$d = function($part) use ($parts) {
268
+			return !is_null($parts[$part]);
269
+		};
270
+
271
+		$r = function($part) use ($parts) {
272
+			return $parts[$part];
273
+		};
274
+
275
+		// From the Relax NG Schema.
276
+		//
277
+		// # 4.3.1
278
+		// value-date = element date {
279
+		//     xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" }
280
+		//   }
281
+		if (($d('year') ||  $d('month')  ||  $d('date'))
282
+			&& (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) {
283
+
284
+			if ($d('year') && $d('month') && $d('date')) {
285
+				$value .= $r('year') . $r('month') . $r('date');
286
+			} elseif ($d('year') && $d('month') && !$d('date')) {
287
+				$value .= $r('year') . '-' . $r('month');
288
+			} elseif (!$d('year') && $d('month')) {
289
+				$value .= '--' . $r('month') . $r('date');
290
+			} elseif (!$d('year') && !$d('month') && $d('date')) {
291
+				$value .= '---' . $r('date');
292
+			}
293
+
294
+		// # 4.3.2
295
+		// value-time = element time {
296
+		//     xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)"
297
+		//                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
298
+		//   }
299
+		} elseif ((!$d('year') && !$d('month')  && !$d('date'))
300
+				  && ($d('hour') ||  $d('minute') ||  $d('second'))) {
301
+
302
+			if ($d('hour')) {
303
+				$value .= $r('hour') . $r('minute') . $r('second');
304
+			} elseif ($d('minute')) {
305
+				$value .= '-' . $r('minute') . $r('second');
306
+			} elseif ($d('second')) {
307
+				$value .= '--' . $r('second');
308
+			}
309
+
310
+			$value .= $r('timezone');
311
+
312
+		// # 4.3.3
313
+		// value-date-time = element date-time {
314
+		//     xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?"
315
+		//                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
316
+		//   }
317
+		} elseif ($d('date') && $d('hour')) {
318
+
319
+			if ($d('year') && $d('month') && $d('date')) {
320
+				$value .= $r('year') . $r('month') . $r('date');
321
+			} elseif (!$d('year') && $d('month') && $d('date')) {
322
+				$value .= '--' . $r('month') . $r('date');
323
+			} elseif (!$d('year') && !$d('month') && $d('date')) {
324
+				$value .= '---' . $r('date');
325
+			}
326
+
327
+			$value .= 'T' . $r('hour') . $r('minute') . $r('second') .
328
+					  $r('timezone');
329
+
330
+		}
331
+
332
+		$writer->writeElement($valueType, $value);
333
+
334
+	}
335
+
336
+	/**
337
+	 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
338
+	 *
339
+	 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
340
+	 * not yet done, but parameters are not included.
341
+	 *
342
+	 * @param string $val
343
+	 *
344
+	 * @return void
345
+	 */
346
+	public function setRawMimeDirValue($val) {
347
+
348
+		$this->setValue($val);
349
+
350
+	}
351
+
352
+	/**
353
+	 * Returns a raw mime-dir representation of the value.
354
+	 *
355
+	 * @return string
356
+	 */
357
+	public function getRawMimeDirValue() {
358
+
359
+		return implode($this->delimiter, $this->getParts());
360
+
361
+	}
362
+
363
+	/**
364
+	 * Validates the node for correctness.
365
+	 *
366
+	 * The following options are supported:
367
+	 *   Node::REPAIR - May attempt to automatically repair the problem.
368
+	 *
369
+	 * This method returns an array with detected problems.
370
+	 * Every element has the following properties:
371
+	 *
372
+	 *  * level - problem level.
373
+	 *  * message - A human-readable string describing the issue.
374
+	 *  * node - A reference to the problematic node.
375
+	 *
376
+	 * The level means:
377
+	 *   1 - The issue was repaired (only happens if REPAIR was turned on)
378
+	 *   2 - An inconsequential issue
379
+	 *   3 - A severe issue.
380
+	 *
381
+	 * @param int $options
382
+	 *
383
+	 * @return array
384
+	 */
385
+	public function validate($options = 0) {
386
+
387
+		$messages = parent::validate($options);
388
+		$value = $this->getValue();
389
+
390
+		try {
391
+			DateTimeParser::parseVCardDateTime($value);
392
+		} catch (InvalidDataException $e) {
393
+			$messages[] = [
394
+				'level'   => 3,
395
+				'message' => 'The supplied value (' . $value . ') is not a correct DATE-AND-OR-TIME property',
396
+				'node'    => $this,
397
+			];
398
+		}
399
+
400
+		return $messages;
401
+
402
+	}
403 403
 }
Please login to merge, or discard this patch.