ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Parameter Class Reference

VObject Parameter. More...

+ Inheritance diagram for Sabre\VObject\Parameter:
+ Collaboration diagram for Sabre\VObject\Parameter:

Public Member Functions

 __construct (Document $root, $name, $value=null)
 Sets up the object. More...
 
 setValue ($value)
 Updates the current value. More...
 
 getValue ()
 Returns the current value. More...
 
 setParts (array $value)
 Sets multiple values for this parameter. More...
 
 getParts ()
 Returns all values for this parameter. More...
 
 addValue ($part)
 Adds a value to this parameter. More...
 
 has ($value)
 Checks if this parameter contains the specified value. More...
 
 serialize ()
 Turns the object back into a serialized blob. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 __toString ()
 Called when this object is being cast to a string. More...
 
 getIterator ()
 Returns the iterator for this object. More...
 
- Public Member Functions inherited from Sabre\VObject\Node
 serialize ()
 Serializes the node into a mimedir format. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 destroy ()
 Call this method on a document if you're done using it. More...
 
 getIterator ()
 Returns the iterator for this object. More...
 
 setIterator (ElementList $iterator)
 Sets the overridden iterator. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 count ()
 Returns the number of elements. More...
 
 offsetExists ($offset)
 Checks if an item exists through ArrayAccess. More...
 
 offsetGet ($offset)
 Gets an item through ArrayAccess. More...
 
 offsetSet ($offset, $value)
 Sets an item through ArrayAccess. More...
 
 offsetUnset ($offset)
 Sets an item through ArrayAccess. More...
 
- Public Member Functions inherited from Sabre\Xml\XmlSerializable
 xmlSerialize (Writer $writer)
 The xmlSerialize method is called during xml writing. More...
 

Static Public Member Functions

static guessParameterNameByValue ($value)
 Try to guess property name by value, can be used for vCard 2.1 nameless parameters. More...
 

Data Fields

 $name
 
 $noName = false
 
- Data Fields inherited from Sabre\VObject\Node
const REPAIR = 1
 The following constants are used by the validate() method. More...
 
const PROFILE_CARDDAV = 2
 If this option is set, the validator will operate on the vcards on the assumption that the vcards need to be valid for CardDAV. More...
 
const PROFILE_CALDAV = 4
 If this option is set, the validator will operate on iCalendar objects on the assumption that the vcards need to be valid for CalDAV. More...
 
 $parent
 

Protected Attributes

 $value
 
- Protected Attributes inherited from Sabre\VObject\Node
 $iterator = null
 
 $root
 

Detailed Description

VObject Parameter.

This class represents a parameter. A parameter is always tied to a property. In the case of: DTSTART;VALUE=DATE:20101108 VALUE=DATE would be the parameter name and value.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 20 of file Parameter.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\Parameter::__construct ( Document  $root,
  $name,
  $value = null 
)

Sets up the object.

It's recommended to use the create:: factory method instead.

Parameters
string$name
string$value

Definition at line 53 of file Parameter.php.

53 {
54
55 $this->name = strtoupper($name);
56 $this->root = $root;
57 if (is_null($name)) {
58 $this->noName = true;
59 $this->name = static::guessParameterNameByValue($value);
60 }
61
62 // If guessParameterNameByValue() returns an empty string
63 // above, we're actually dealing with a parameter that has no value.
64 // In that case we have to move the value to the name.
65 if ($this->name === '') {
66 $this->noName = false;
67 $this->name = strtoupper($value);
68 } else {
69 $this->setValue($value);
70 }
71
72 }
setValue($value)
Updates the current value.
Definition: Parameter.php:183

References Sabre\VObject\Parameter\$name, Sabre\VObject\Node\$root, Sabre\VObject\Parameter\$value, and Sabre\VObject\Parameter\setValue().

+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

Sabre\VObject\Parameter::__toString ( )

Called when this object is being cast to a string.

Returns
string

Definition at line 374 of file Parameter.php.

374 {
375
376 return (string)$this->getValue();
377
378 }
getValue()
Returns the current value.
Definition: Parameter.php:197

References Sabre\VObject\Parameter\getValue().

+ Here is the call graph for this function:

◆ addValue()

Sabre\VObject\Parameter::addValue (   $part)

Adds a value to this parameter.

If the argument is specified as an array, all items will be added to the parameter value list.

Parameters
string | array$part
Returns
void

Definition at line 249 of file Parameter.php.

249 {
250
251 if (is_null($this->value)) {
252 $this->value = $part;
253 } else {
254 $this->value = array_merge((array)$this->value, (array)$part);
255 }
256
257 }

◆ getIterator()

Sabre\VObject\Parameter::getIterator ( )

Returns the iterator for this object.

Returns
ElementList

Reimplemented from Sabre\VObject\Node.

Definition at line 385 of file Parameter.php.

385 {
386
387 if (!is_null($this->iterator))
388 return $this->iterator;
389
390 return $this->iterator = new ArrayIterator((array)$this->value);
391
392 }

References Sabre\VObject\Node\$iterator.

◆ getParts()

Sabre\VObject\Parameter::getParts ( )

Returns all values for this parameter.

If there were no values, an empty array will be returned.

Returns
array

Definition at line 227 of file Parameter.php.

227 {
228
229 if (is_array($this->value)) {
230 return $this->value;
231 } elseif (is_null($this->value)) {
232 return [];
233 } else {
234 return [$this->value];
235 }
236
237 }

References Sabre\VObject\Parameter\$value.

Referenced by Sabre\VObject\Parameter\serialize().

+ Here is the caller graph for this function:

◆ getValue()

Sabre\VObject\Parameter::getValue ( )

Returns the current value.

This method will always return a string, or null. If there were multiple values, it will automatically concatenate them (separated by comma).

Returns
string|null

Definition at line 197 of file Parameter.php.

197 {
198
199 if (is_array($this->value)) {
200 return implode(',', $this->value);
201 } else {
202 return $this->value;
203 }
204
205 }

References Sabre\VObject\Parameter\$value.

Referenced by Sabre\VObject\Parameter\__toString().

+ Here is the caller graph for this function:

◆ guessParameterNameByValue()

static Sabre\VObject\Parameter::guessParameterNameByValue (   $value)
static

Try to guess property name by value, can be used for vCard 2.1 nameless parameters.

Figuring out what the name should have been. Note that a ton of these are rather silly in 2014 and would probably rarely be used, but we like to be complete.

Parameters
string$value
Returns
string

Definition at line 85 of file Parameter.php.

85 {
86 switch (strtoupper($value)) {
87
88 // Encodings
89 case '7-BIT' :
90 case 'QUOTED-PRINTABLE' :
91 case 'BASE64' :
92 $name = 'ENCODING';
93 break;
94
95 // Common types
96 case 'WORK' :
97 case 'HOME' :
98 case 'PREF' :
99
100 // Delivery Label Type
101 case 'DOM' :
102 case 'INTL' :
103 case 'POSTAL' :
104 case 'PARCEL' :
105
106 // Telephone types
107 case 'VOICE' :
108 case 'FAX' :
109 case 'MSG' :
110 case 'CELL' :
111 case 'PAGER' :
112 case 'BBS' :
113 case 'MODEM' :
114 case 'CAR' :
115 case 'ISDN' :
116 case 'VIDEO' :
117
118 // EMAIL types (lol)
119 case 'AOL' :
120 case 'APPLELINK' :
121 case 'ATTMAIL' :
122 case 'CIS' :
123 case 'EWORLD' :
124 case 'INTERNET' :
125 case 'IBMMAIL' :
126 case 'MCIMAIL' :
127 case 'POWERSHARE' :
128 case 'PRODIGY' :
129 case 'TLX' :
130 case 'X400' :
131
132 // Photo / Logo format types
133 case 'GIF' :
134 case 'CGM' :
135 case 'WMF' :
136 case 'BMP' :
137 case 'DIB' :
138 case 'PICT' :
139 case 'TIFF' :
140 case 'PDF' :
141 case 'PS' :
142 case 'JPEG' :
143 case 'MPEG' :
144 case 'MPEG2' :
145 case 'AVI' :
146 case 'QTIME' :
147
148 // Sound Digital Audio Type
149 case 'WAVE' :
150 case 'PCM' :
151 case 'AIFF' :
152
153 // Key types
154 case 'X509' :
155 case 'PGP' :
156 $name = 'TYPE';
157 break;
158
159 // Value types
160 case 'INLINE' :
161 case 'URL' :
162 case 'CONTENT-ID' :
163 case 'CID' :
164 $name = 'VALUE';
165 break;
166
167 default:
168 $name = '';
169 }
170
171 return $name;
172 }

References Sabre\VObject\Parameter\$name, and Sabre\VObject\Parameter\$value.

Referenced by Sabre\VObject\Property\add().

+ Here is the caller graph for this function:

◆ has()

Sabre\VObject\Parameter::has (   $value)

Checks if this parameter contains the specified value.

This is a case-insensitive match. It makes sense to call this for for instance the TYPE parameter, to see if it contains a keyword such as 'WORK' or 'FAX'.

Parameters
string$value
Returns
bool

Definition at line 270 of file Parameter.php.

270 {
271
272 return in_array(
273 strtolower($value),
274 array_map('strtolower', (array)$this->value)
275 );
276
277 }

References Sabre\VObject\Parameter\$value.

◆ jsonSerialize()

Sabre\VObject\Parameter::jsonSerialize ( )

This method returns an array, with the representation as it should be encoded in JSON.

This is used to create jCard or jCal documents.

Returns
array

Reimplemented from Sabre\VObject\Node.

Definition at line 347 of file Parameter.php.

347 {
348
349 return $this->value;
350
351 }

References Sabre\VObject\Parameter\$value.

◆ serialize()

Sabre\VObject\Parameter::serialize ( )

Turns the object back into a serialized blob.

Returns
string

Reimplemented from Sabre\VObject\Node.

Definition at line 284 of file Parameter.php.

284 {
285
286 $value = $this->getParts();
287
288 if (count($value) === 0) {
289 return $this->name . '=';
290 }
291
292 if ($this->root->getDocumentType() === Document::VCARD21 && $this->noName) {
293
294 return implode(';', $value);
295
296 }
297
298 return $this->name . '=' . array_reduce(
299 $value,
300 function($out, $item) {
301
302 if (!is_null($out)) $out .= ',';
303
304 // If there's no special characters in the string, we'll use the simple
305 // format.
306 //
307 // The list of special characters is defined as:
308 //
309 // Any character except CONTROL, DQUOTE, ";", ":", ","
310 //
311 // by the iCalendar spec:
312 // https://tools.ietf.org/html/rfc5545#section-3.1
313 //
314 // And we add ^ to that because of:
315 // https://tools.ietf.org/html/rfc6868
316 //
317 // But we've found that iCal (7.0, shipped with OSX 10.9)
318 // severaly trips on + characters not being quoted, so we
319 // added + as well.
320 if (!preg_match('#(?: [\n":;\^,\+] )#x', $item)) {
321 return $out . $item;
322 } else {
323 // Enclosing in double-quotes, and using RFC6868 for encoding any
324 // special characters
325 $out .= '"' . strtr(
326 $item,
327 [
328 '^' => '^^',
329 "\n" => '^n',
330 '"' => '^\'',
331 ]
332 ) . '"';
333 return $out;
334 }
335
336 }
337 );
338
339 }
const VCARD21
vCard 2.1.
Definition: Document.php:39
count()
Returns the number of elements.
Definition: Node.php:177
getParts()
Returns all values for this parameter.
Definition: Parameter.php:227

References $out, Sabre\VObject\Parameter\$value, Sabre\VObject\Node\count(), Sabre\VObject\Parameter\getParts(), and Sabre\VObject\Document\VCARD21.

+ Here is the call graph for this function:

◆ setParts()

Sabre\VObject\Parameter::setParts ( array  $value)

Sets multiple values for this parameter.

Parameters
array$value
Returns
void

Definition at line 214 of file Parameter.php.

214 {
215
216 $this->value = $value;
217
218 }

References Sabre\VObject\Parameter\$value.

◆ setValue()

Sabre\VObject\Parameter::setValue (   $value)

Updates the current value.

This may be either a single, or multiple strings in an array.

Parameters
string | array$value
Returns
void

Definition at line 183 of file Parameter.php.

183 {
184
185 $this->value = $value;
186
187 }

References Sabre\VObject\Parameter\$value.

Referenced by Sabre\VObject\Parameter\__construct().

+ Here is the caller graph for this function:

◆ xmlSerialize()

Sabre\VObject\Parameter::xmlSerialize ( Xml\Writer  $writer)

This method serializes the data into XML.

This is used to create xCard or xCal documents.

Parameters
Xml\Writer$writerXML writer.
Returns
void

Reimplemented from Sabre\VObject\Node.

Definition at line 361 of file Parameter.php.

361 {
362
363 foreach (explode(',', $this->value) as $value) {
364 $writer->writeElement('text', $value);
365 }
366
367 }

References Sabre\VObject\Parameter\$value.

Field Documentation

◆ $name

Sabre\VObject\Parameter::$name

◆ $noName

Sabre\VObject\Parameter::$noName = false

Definition at line 36 of file Parameter.php.

◆ $value


The documentation for this class was generated from the following file: