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

Text property. More...

+ Inheritance diagram for Sabre\VObject\Property\Text:
+ Collaboration diagram for Sabre\VObject\Property\Text:

Public Member Functions

 __construct (Component $root, $name, $value=null, array $parameters=[], $group=null)
 Creates the property. More...
 
 setRawMimeDirValue ($val)
 Sets a raw value coming from a mimedir (iCalendar/vCard) file. More...
 
 setQuotedPrintableValue ($val)
 Sets the value as a quoted-printable encoded string. More...
 
 getRawMimeDirValue ()
 Returns a raw mime-dir representation of the value. More...
 
 getJsonValue ()
 Returns the value, in the format it should be encoded for json. More...
 
 getValueType ()
 Returns the type of value. More...
 
 serialize ()
 Turns the object back into a serialized blob. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
- Public Member Functions inherited from Sabre\VObject\Property
 __construct (Component $root, $name, $value=null, array $parameters=[], $group=null)
 Creates the generic property. More...
 
 setValue ($value)
 Updates the current value. More...
 
 getValue ()
 Returns the current value. More...
 
 setParts (array $parts)
 Sets a multi-valued property. More...
 
 getParts ()
 Returns a multi-valued property. More...
 
 add ($name, $value=null)
 Adds a new parameter. More...
 
 parameters ()
 Returns an iterable list of children. More...
 
 getValueType ()
 Returns the type of value. More...
 
 setRawMimeDirValue ($val)
 Sets a raw value coming from a mimedir (iCalendar/vCard) file. More...
 
 getRawMimeDirValue ()
 Returns a raw mime-dir representation of the value. More...
 
 serialize ()
 Turns the object back into a serialized blob. More...
 
 getJsonValue ()
 Returns the value, in the format it should be encoded for JSON. More...
 
 setJsonValue (array $value)
 Sets the JSON value, as it would appear in a jCard or jCal object. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 setXmlValue (array $value)
 Hydrate data from a XML subtree, as it would appear in a xCard or xCal object. 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...
 
 offsetExists ($name)
 Checks if an array element exists. More...
 
 offsetGet ($name)
 Returns a parameter. More...
 
 offsetSet ($name, $value)
 Creates a new parameter. More...
 
 offsetUnset ($name)
 Removes one or more parameters with the specified name. More...
 
 __clone ()
 This method is automatically called when the object is cloned. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 destroy ()
 Call this method on a document if you're done using it. 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...
 

Data Fields

 $delimiter = ','
 
- Data Fields inherited from Sabre\VObject\Property
 $name
 
 $group
 
 $parameters = []
 
 $delimiter = ';'
 
- 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 Member Functions

 xmlSerializeValue (Xml\Writer $writer)
 This method serializes only the value of a property. More...
 
 xmlSerializeValue (Xml\Writer $writer)
 This method serializes only the value of a property. More...
 

Protected Attributes

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

Detailed Description

Text property.

This object represents TEXT values.

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

Definition at line 20 of file Text.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\Property\Text::__construct ( Component  $root,
  $name,
  $value = null,
array  $parameters = [],
  $group = null 
)

Creates the property.

You can specify the parameters either in key=>value syntax, in which case parameters will automatically be created, or you can just pass a list of Parameter objects.

Parameters
Component$rootThe root document
string$name
string | array | null$value
array$parametersList of parameters
string$groupThe vcard property group
Returns
void

Reimplemented from Sabre\VObject\Property.

Definition at line 75 of file Text.php.

75 {
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 }

References Sabre\VObject\Property\$group, Sabre\VObject\Property\$name, Sabre\VObject\Property\$parameters, Sabre\VObject\Node\$root, and Sabre\VObject\Property\$value.

Member Function Documentation

◆ getJsonValue()

Sabre\VObject\Property\Text::getJsonValue ( )

Returns the value, in the format it should be encoded for json.

This method must always return an array.

Returns
array

Reimplemented from Sabre\VObject\Property.

Reimplemented in Sabre\VObject\Property\Time, Sabre\VObject\Property\Unknown, Sabre\VObject\Property\UtcOffset, and Sabre\VObject\Property\VCard\TimeStamp.

Definition at line 175 of file Text.php.

175 {
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 }
getParts()
Returns a multi-valued property.
Definition: Property.php:152

References Sabre\VObject\Property\getParts().

+ Here is the call graph for this function:

◆ getRawMimeDirValue()

Sabre\VObject\Property\Text::getRawMimeDirValue ( )

Returns a raw mime-dir representation of the value.

Returns
string

Reimplemented from Sabre\VObject\Property.

Reimplemented in Sabre\VObject\Property\Uri.

Definition at line 134 of file Text.php.

134 {
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 }

References Sabre\VObject\Property\getParts().

Referenced by Sabre\VObject\Property\Unknown\getJsonValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValueType()

Sabre\VObject\Property\Text::getValueType ( )

Returns the type of value.

This corresponds to the VALUE= parameter. Every property also has a 'default' valueType.

Returns
string

Reimplemented from Sabre\VObject\Property.

Reimplemented in Sabre\VObject\Property\ICalendar\CalAddress, Sabre\VObject\Property\Time, Sabre\VObject\Property\Unknown, Sabre\VObject\Property\Uri, Sabre\VObject\Property\UtcOffset, and Sabre\VObject\Property\VCard\TimeStamp.

Definition at line 195 of file Text.php.

195 {
196
197 return 'TEXT';
198
199 }

◆ serialize()

Sabre\VObject\Property\Text::serialize ( )

Turns the object back into a serialized blob.

Returns
string

Reimplemented from Sabre\VObject\Property.

Definition at line 206 of file Text.php.

206 {
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
276 $str = \preg_replace(
277 '/(
278 (?:^.)? # 1 additional byte in first line because of missing single space (see next line)
279 .{1,74} # max 75 bytes per line (1 byte is used for a single space added after every CRLF)
280 (?![\x80-\xbf]) # prevent splitting multibyte characters
281 )/x',
282 "$1\r\n ",
283 $str
284 );
285
286 // remove single space after last CRLF
287 return \substr($str, 0, -1);
288
289 }
290
291 }
const VCARD21
vCard 2.1.
Definition: Document.php:39
count()
Returns the number of elements.
Definition: Node.php:177
parameters()
Returns an iterable list of children.
Definition: Property.php:196

References $ii, Sabre\VObject\Property\$name, $out, Sabre\VObject\Node\count(), Sabre\VObject\Property\getParts(), Sabre\VObject\Property\parameters(), and Sabre\VObject\Document\VCARD21.

+ Here is the call graph for this function:

◆ setQuotedPrintableValue()

Sabre\VObject\Property\Text::setQuotedPrintableValue (   $val)

Sets the value as a quoted-printable encoded string.

Parameters
string$val
Returns
void

Reimplemented in Sabre\VObject\Property\FlatText.

Definition at line 113 of file Text.php.

113 {
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 }
setValue($value)
Updates the current value.
Definition: Property.php:98

References Sabre\VObject\Property\setValue().

+ Here is the call graph for this function:

◆ setRawMimeDirValue()

Sabre\VObject\Property\Text::setRawMimeDirValue (   $val)

Sets a raw value coming from a mimedir (iCalendar/vCard) file.

This has been 'unfolded', so only 1 line will be passed. Unescaping is not yet done, but parameters are not included.

Parameters
string$val
Returns
void

Reimplemented from Sabre\VObject\Property.

Reimplemented in Sabre\VObject\Property\Uri.

Definition at line 100 of file Text.php.

100 {
101
102 $this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
103
104 }
static unescapeValue($input, $delimiter=';')
Unescapes a property value.
Definition: MimeDir.php:549

References Sabre\VObject\Property\setValue(), and Sabre\VObject\Parser\MimeDir\unescapeValue().

+ Here is the call graph for this function:

◆ validate()

Sabre\VObject\Property\Text::validate (   $options = 0)

Validates the node for correctness.

The following options are supported:

  • Node::REPAIR - If something is broken, and automatic repair may be attempted.

An array is returned with warnings.

Every item in the array has the following properties:

  • level - (number between 1 and 3 with severity information)
  • message - (human readable message)
  • node - (reference to the offending node)
Parameters
int$options
Returns
array

Reimplemented from Sabre\VObject\Property.

Definition at line 389 of file Text.php.

389 {
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 }
setParts(array $parts)
Sets a multi-valued property.
Definition: Property.php:138

References Sabre\VObject\Property\$name, PHPMailer\PHPMailer\$options, $warnings, Sabre\VObject\Node\count(), Sabre\VObject\Property\getParts(), and Sabre\VObject\Property\setParts().

+ Here is the call graph for this function:

◆ xmlSerializeValue()

Sabre\VObject\Property\Text::xmlSerializeValue ( Xml\Writer  $writer)
protected

This method serializes only the value of a property.

This is used to create xCard or xCal documents.

Parameters
Xml\Writer$writerXML writer.
Returns
void

Reimplemented from Sabre\VObject\Property.

Reimplemented in Sabre\VObject\Property\VCard\TimeStamp.

Definition at line 301 of file Text.php.

301 {
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 }
$i
Definition: disco.tpl.php:19
$values

References $i, $map, $values, and Sabre\VObject\Property\getParts().

+ Here is the call graph for this function:

Field Documentation

◆ $delimiter

Sabre\VObject\Property\Text::$delimiter = ','

Definition at line 28 of file Text.php.

◆ $minimumPropertyValues

Sabre\VObject\Property\Text::$minimumPropertyValues
protected
Initial value:
= [
'N' => 5,
'ADR' => 7,
]

Definition at line 55 of file Text.php.

◆ $structuredValues

Sabre\VObject\Property\Text::$structuredValues
protected
Initial value:
= [
'N',
'ADR',
'ORG',
'GENDER',
'CLIENTPIDMAP',
'REQUEST-STATUS',
]

Definition at line 35 of file Text.php.


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