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

The VCard component. More...

+ Inheritance diagram for Sabre\VObject\Component\VCard:
+ Collaboration diagram for Sabre\VObject\Component\VCard:

Public Member Functions

static getDocumentType ()
 Returns the current document type. More...
 
 convert ($target)
 Converts the document to a different vcard version. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 getValidationRules ()
 
 preferred ($propertyName)
 Returns a preferred field. More...
 
 getByType ($propertyName, $type)
 Returns a property with a specific TYPE value (ADR, TEL, or EMAIL). 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...
 
 getClassNameForPropertyName ($propertyName)
 Returns the default class for a property name. More...
 
- Public Member Functions inherited from Sabre\VObject\Document
 __construct ()
 Creates a new document. More...
 
 getDocumentType ()
 Returns the current document type. More...
 
 create ($name)
 Creates a new component or property. More...
 
 createComponent ($name, array $children=null, $defaults=true)
 Creates a new component. More...
 
 createProperty ($name, $value=null, array $parameters=null, $valueType=null)
 Factory method for creating new properties. More...
 
 getClassNameForPropertyValue ($valueParam)
 This method returns a full class-name for a value parameter. More...
 
 getClassNameForPropertyName ($propertyName)
 Returns the default class for a property name. More...
 
- Public Member Functions inherited from Sabre\VObject\Component
 __construct (Document $root, $name, array $children=[], $defaults=true)
 Creates a new component. More...
 
 add ()
 Adds a new property or component, and returns the new item. More...
 
 remove ($item)
 This method removes a component or property from this component. More...
 
 children ()
 Returns a flat list of all the properties and components in this component. More...
 
 getComponents ()
 This method only returns a list of sub-components. More...
 
 select ($name)
 Returns an array with elements that match the specified name. 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...
 
 __isset ($name)
 This method checks if a sub-element with the specified name exists. More...
 
 __set ($name, $value)
 Using the setter method you can add properties or subcomponents. More...
 
 __unset ($name)
 Removes all properties and components within this component with the specified name. More...
 
 __clone ()
 This method is automatically called when the object is cloned. More...
 
 getValidationRules ()
 
 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

const DEFAULT_VERSION = self::VCARD21
 VCards with version 2.1, 3.0 and 4.0 are found. More...
 
- Data Fields inherited from Sabre\VObject\Document
const UNKNOWN = 1
 Unknown document type. More...
 
const VCALENDAR10 = 2
 vCalendar 1.0. More...
 
const ICALENDAR20 = 3
 iCalendar 2.0. More...
 
const VCARD21 = 4
 vCard 2.1. More...
 
const VCARD30 = 5
 vCard 3.0. More...
 
const VCARD40 = 6
 vCard 4.0. More...
 
- Data Fields inherited from Sabre\VObject\Component
 $name
 
- 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
 

Static Public Attributes

static $defaultName = 'VCARD'
 
static $componentMap
 
static $valueMap
 
static $propertyMap
 
- Static Public Attributes inherited from Sabre\VObject\Document
static $defaultName
 
static $propertyMap = []
 
static $componentMap = []
 
static $valueMap = []
 

Protected Member Functions

 getDefaults ()
 This method should return a list of default property values. More...
 
- Protected Member Functions inherited from Sabre\VObject\Component
 getDefaults ()
 This method should return a list of default property values. More...
 

Private Attributes

 $version = null
 

Additional Inherited Members

- Protected Attributes inherited from Sabre\VObject\Component
 $children = []
 
- Protected Attributes inherited from Sabre\VObject\Node
 $iterator = null
 
 $root
 

Detailed Description

The VCard component.

This component represents the BEGIN:VCARD and END:VCARD found in every vcard.

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

Definition at line 18 of file VCard.php.

Member Function Documentation

◆ convert()

Sabre\VObject\Component\VCard::convert (   $target)

Converts the document to a different vcard version.

Use one of the VCARD constants for the target. This method will return a copy of the vcard in the new version.

At the moment the only supported conversion is from 3.0 to 4.0.

If input and output version are identical, a clone is returned.

Parameters
int$target
Returns
VCard

Definition at line 188 of file VCard.php.

References $target.

188  {
189 
190  $converter = new VObject\VCardConverter();
191  return $converter->convert($this, $target);
192 
193  }
$target
Definition: test.php:19

◆ getByType()

Sabre\VObject\Component\VCard::getByType (   $propertyName,
  $type 
)

Returns a property with a specific TYPE value (ADR, TEL, or EMAIL).

This function will return null if the property does not exist. If there are multiple properties with the same TYPE value, only one will be returned.

Parameters
string$propertyName
string$type
Returns
VObject|null

Definition at line 429 of file VCard.php.

References $type, and Sabre\VObject\Component\select().

429  {
430  foreach ($this->select($propertyName) as $field) {
431  if (isset($field['TYPE']) && $field['TYPE']->has($type)) {
432  return $field;
433  }
434  }
435  }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
$type
+ Here is the call graph for this function:

◆ getClassNameForPropertyName()

Sabre\VObject\Component\VCard::getClassNameForPropertyName (   $propertyName)

Returns the default class for a property name.

Parameters
string$propertyName
Returns
string

Definition at line 546 of file VCard.php.

References Sabre\VObject\Component\VCard\getDocumentType().

546  {
547 
548  $className = parent::getClassNameForPropertyName($propertyName);
549 
550  // In vCard 4, BINARY no longer exists, and we need URI instead.
551  if ($className == 'Sabre\\VObject\\Property\\Binary' && $this->getDocumentType() === self::VCARD40) {
552  return 'Sabre\\VObject\\Property\\Uri';
553  }
554  return $className;
555 
556  }
static getDocumentType()
Returns the current document type.
Definition: VCard.php:147
+ Here is the call graph for this function:

◆ getDefaults()

Sabre\VObject\Component\VCard::getDefaults ( )
protected

This method should return a list of default property values.

Returns
array

Definition at line 442 of file VCard.php.

References Sabre\VObject\UUIDUtil\getUUID(), and Sabre\VObject\Version\VERSION.

442  {
443 
444  return [
445  'VERSION' => '4.0',
446  'PRODID' => '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN',
447  'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
448  ];
449 
450  }
const VERSION
Full version number.
Definition: Version.php:17
static getUUID()
Returns a pseudo-random v4 UUID.
Definition: UUIDUtil.php:27
+ Here is the call graph for this function:

◆ getDocumentType()

static Sabre\VObject\Component\VCard::getDocumentType ( )

Returns the current document type.

Returns
int

Definition at line 147 of file VCard.php.

References Sabre\VObject\Component\VCard\$version.

Referenced by Sabre\VObject\Component\VCard\getClassNameForPropertyName().

147  {
148 
149  if (!$this->version) {
150 
151  $version = (string)$this->VERSION;
152 
153  switch ($version) {
154  case '2.1' :
155  $this->version = self::VCARD21;
156  break;
157  case '3.0' :
158  $this->version = self::VCARD30;
159  break;
160  case '4.0' :
161  $this->version = self::VCARD40;
162  break;
163  default :
164  // We don't want to cache the version if it's unknown,
165  // because we might get a version property in a bit.
166  return self::UNKNOWN;
167  }
168  }
169 
170  return $this->version;
171 
172  }
+ Here is the caller graph for this function:

◆ getValidationRules()

Sabre\VObject\Component\VCard::getValidationRules ( )

Definition at line 335 of file VCard.php.

335  {
336 
337  return [
338  'ADR' => '*',
339  'ANNIVERSARY' => '?',
340  'BDAY' => '?',
341  'CALADRURI' => '*',
342  'CALURI' => '*',
343  'CATEGORIES' => '*',
344  'CLIENTPIDMAP' => '*',
345  'EMAIL' => '*',
346  'FBURL' => '*',
347  'IMPP' => '*',
348  'GENDER' => '?',
349  'GEO' => '*',
350  'KEY' => '*',
351  'KIND' => '?',
352  'LANG' => '*',
353  'LOGO' => '*',
354  'MEMBER' => '*',
355  'N' => '?',
356  'NICKNAME' => '*',
357  'NOTE' => '*',
358  'ORG' => '*',
359  'PHOTO' => '*',
360  'PRODID' => '?',
361  'RELATED' => '*',
362  'REV' => '?',
363  'ROLE' => '*',
364  'SOUND' => '*',
365  'SOURCE' => '*',
366  'TEL' => '*',
367  'TITLE' => '*',
368  'TZ' => '*',
369  'URL' => '*',
370  'VERSION' => '1',
371  'XML' => '*',
372 
373  // FN is commented out, because it's already handled by the
374  // validate function, which may also try to repair it.
375  // 'FN' => '+',
376  'UID' => '?',
377  ];
378 
379  }

◆ jsonSerialize()

Sabre\VObject\Component\VCard::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

Definition at line 458 of file VCard.php.

References Sabre\VObject\Component\children().

458  {
459 
460  // A vcard does not have sub-components, so we're overriding this
461  // method to remove that array element.
462  $properties = [];
463 
464  foreach ($this->children() as $child) {
465  $properties[] = $child->jsonSerialize();
466  }
467 
468  return [
469  strtolower($this->name),
470  $properties,
471  ];
472 
473  }
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

◆ preferred()

Sabre\VObject\Component\VCard::preferred (   $propertyName)

Returns a preferred field.

VCards can indicate wether a field such as ADR, TEL or EMAIL is preferred by specifying TYPE=PREF (vcard 2.1, 3) or PREF=x (vcard 4, x being a number between 1 and 100).

If neither of those parameters are specified, the first is returned, if a field with that name does not exist, null is returned.

Parameters
string$fieldName
Returns
VObject|null

Definition at line 395 of file VCard.php.

References Sabre\VObject\Component\select().

395  {
396 
397  $preferred = null;
398  $lastPref = 101;
399  foreach ($this->select($propertyName) as $field) {
400 
401  $pref = 101;
402  if (isset($field['TYPE']) && $field['TYPE']->has('PREF')) {
403  $pref = 1;
404  } elseif (isset($field['PREF'])) {
405  $pref = $field['PREF']->getValue();
406  }
407 
408  if ($pref < $lastPref || is_null($preferred)) {
409  $preferred = $field;
410  $lastPref = $pref;
411  }
412 
413  }
414  return $preferred;
415 
416  }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
+ Here is the call graph for this function:

◆ validate()

Sabre\VObject\Component\VCard::validate (   $options = 0)

Validates the node for correctness.

The following options are supported: Node::REPAIR - May attempt to automatically repair the problem.

This method returns an array with detected problems. Every element has the following properties:

  • level - problem level.
  • message - A human-readable string describing the issue.
  • node - A reference to the problematic node.

The level means: 1 - The issue was repaired (only happens if REPAIR was turned on) 2 - An inconsequential issue 3 - A severe issue.

Parameters
int$options
Returns
array

Definition at line 224 of file VCard.php.

References $message, PHPMailer\PHPMailer\$options, Sabre\VObject\Component\VCard\$version, $warnings, Sabre\VObject\Node\count(), Sabre\VObject\UUIDUtil\getUUID(), and Sabre\VObject\Component\select().

224  {
225 
226  $warnings = [];
227 
228  $versionMap = [
229  self::VCARD21 => '2.1',
230  self::VCARD30 => '3.0',
231  self::VCARD40 => '4.0',
232  ];
233 
234  $version = $this->select('VERSION');
235  if (count($version) === 1) {
236  $version = (string)$this->VERSION;
237  if ($version !== '2.1' && $version !== '3.0' && $version !== '4.0') {
238  $warnings[] = [
239  'level' => 3,
240  'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
241  'node' => $this,
242  ];
243  if ($options & self::REPAIR) {
244  $this->VERSION = $versionMap[self::DEFAULT_VERSION];
245  }
246  }
247  if ($version === '2.1' && ($options & self::PROFILE_CARDDAV)) {
248  $warnings[] = [
249  'level' => 3,
250  'message' => 'CardDAV servers are not allowed to accept vCard 2.1.',
251  'node' => $this,
252  ];
253  }
254 
255  }
256  $uid = $this->select('UID');
257  if (count($uid) === 0) {
258  if ($options & self::PROFILE_CARDDAV) {
259  // Required for CardDAV
260  $warningLevel = 3;
261  $message = 'vCards on CardDAV servers MUST have a UID property.';
262  } else {
263  // Not required for regular vcards
264  $warningLevel = 2;
265  $message = 'Adding a UID to a vCard property is recommended.';
266  }
267  if ($options & self::REPAIR) {
268  $this->UID = VObject\UUIDUtil::getUUID();
269  $warningLevel = 1;
270  }
271  $warnings[] = [
272  'level' => $warningLevel,
273  'message' => $message,
274  'node' => $this,
275  ];
276  }
277 
278  $fn = $this->select('FN');
279  if (count($fn) !== 1) {
280 
281  $repaired = false;
282  if (($options & self::REPAIR) && count($fn) === 0) {
283  // We're going to try to see if we can use the contents of the
284  // N property.
285  if (isset($this->N)) {
286  $value = explode(';', (string)$this->N);
287  if (isset($value[1]) && $value[1]) {
288  $this->FN = $value[1] . ' ' . $value[0];
289  } else {
290  $this->FN = $value[0];
291  }
292  $repaired = true;
293 
294  // Otherwise, the ORG property may work
295  } elseif (isset($this->ORG)) {
296  $this->FN = (string)$this->ORG;
297  $repaired = true;
298 
299  // Otherwise, the EMAIL property may work
300  } elseif (isset($this->EMAIL)) {
301  $this->FN = (string)$this->EMAIL;
302  $repaired = true;
303  }
304 
305  }
306  $warnings[] = [
307  'level' => $repaired ? 1 : 3,
308  'message' => 'The FN property must appear in the VCARD component exactly 1 time',
309  'node' => $this,
310  ];
311  }
312 
313  return array_merge(
314  parent::validate($options),
315  $warnings
316  );
317 
318  }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
catch(Exception $e) $message
count()
Returns the number of elements.
Definition: Node.php:177
static getUUID()
Returns a pseudo-random v4 UUID.
Definition: UUIDUtil.php:27
+ Here is the call graph for this function:

◆ xmlSerialize()

Sabre\VObject\Component\VCard::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

Definition at line 483 of file VCard.php.

References Sabre\VObject\Component\children().

483  {
484 
485  $propertiesByGroup = [];
486 
487  foreach ($this->children() as $property) {
488 
489  $group = $property->group;
490 
491  if (!isset($propertiesByGroup[$group])) {
492  $propertiesByGroup[$group] = [];
493  }
494 
495  $propertiesByGroup[$group][] = $property;
496 
497  }
498 
499  $writer->startElement(strtolower($this->name));
500 
501  foreach ($propertiesByGroup as $group => $properties) {
502 
503  if (!empty($group)) {
504 
505  $writer->startElement('group');
506  $writer->writeAttribute('name', strtolower($group));
507 
508  }
509 
510  foreach ($properties as $property) {
511  switch ($property->name) {
512 
513  case 'VERSION':
514  continue;
515 
516  case 'XML':
517  $value = $property->getParts();
518  $fragment = new Xml\Element\XmlFragment($value[0]);
519  $writer->write($fragment);
520  break;
521 
522  default:
523  $property->xmlSerialize($writer);
524  break;
525 
526  }
527  }
528 
529  if (!empty($group)) {
530  $writer->endElement();
531  }
532 
533  }
534 
535  $writer->endElement();
536 
537  }
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

Field Documentation

◆ $componentMap

Sabre\VObject\Component\VCard::$componentMap
static
Initial value:
= [
'VCARD' => 'Sabre\\VObject\\Component\\VCard'

Definition at line 41 of file VCard.php.

Referenced by Sabre\VObject\Parser\MimeDir\parseDocument().

◆ $defaultName

Sabre\VObject\Component\VCard::$defaultName = 'VCARD'
static

Definition at line 27 of file VCard.php.

◆ $propertyMap

Sabre\VObject\Component\VCard::$propertyMap
static
Initial value:
= [
'N' => 'Sabre\\VObject\\Property\\Text'

Definition at line 74 of file VCard.php.

◆ $valueMap

Sabre\VObject\Component\VCard::$valueMap
static
Initial value:
= [
'BINARY' => 'Sabre\\VObject\\Property\\Binary'

Definition at line 50 of file VCard.php.

◆ $version

Sabre\VObject\Component\VCard::$version = null
private

◆ DEFAULT_VERSION

const Sabre\VObject\Component\VCard::DEFAULT_VERSION = self::VCARD21

VCards with version 2.1, 3.0 and 4.0 are found.

If the VCARD doesn't know its version, 2.1 is assumed.

Definition at line 200 of file VCard.php.


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