7
|
1 <?php
|
|
2
|
|
3 namespace Sabre\VObject\Property;
|
|
4
|
|
5 use
|
|
6 LogicException,
|
|
7 Sabre\VObject\Property;
|
|
8
|
|
9 /**
|
|
10 * BINARY property
|
|
11 *
|
|
12 * This object represents BINARY values.
|
|
13 *
|
|
14 * Binary values are most commonly used by the iCalendar ATTACH property, and
|
|
15 * the vCard PHOTO property.
|
|
16 *
|
|
17 * This property will transparently encode and decode to base64.
|
|
18 *
|
|
19 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
|
|
20 * @author Evert Pot (http://evertpot.com/)
|
|
21 * @license http://sabre.io/license/ Modified BSD License
|
|
22 */
|
|
23 class Binary extends Property {
|
|
24
|
|
25 /**
|
|
26 * In case this is a multi-value property. This string will be used as a
|
|
27 * delimiter.
|
|
28 *
|
|
29 * @var string|null
|
|
30 */
|
|
31 public $delimiter = null;
|
|
32
|
|
33 /**
|
|
34 * Updates the current value.
|
|
35 *
|
|
36 * This may be either a single, or multiple strings in an array.
|
|
37 *
|
|
38 * @param string|array $value
|
|
39 * @return void
|
|
40 */
|
|
41 public function setValue($value) {
|
|
42
|
|
43 if(is_array($value)) {
|
|
44
|
|
45 if(count($value) === 1) {
|
|
46 $this->value = $value[0];
|
|
47 } else {
|
|
48 throw new \InvalidArgumentException('The argument must either be a string or an array with only one child');
|
|
49 }
|
|
50
|
|
51 } else {
|
|
52
|
|
53 $this->value = $value;
|
|
54
|
|
55 }
|
|
56
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
|
61 *
|
|
62 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
|
63 * not yet done, but parameters are not included.
|
|
64 *
|
|
65 * @param string $val
|
|
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 array(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 * @return void
|
|
119 */
|
|
120 public function setJsonValue(array $value) {
|
|
121
|
|
122 $value = array_map('base64_decode', $value);
|
|
123 parent::setJsonValue($value);
|
|
124
|
|
125 }
|
|
126
|
|
127 }
|