3 namespace Sabre\VObject\Component;
10 * This component represents the BEGIN:VCARD and END:VCARD found in every
13 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
14 * @author Evert Pot (http://www.rooftopsolutions.nl/)
15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
17 class VCard extends VObject\Component {
20 * VCards with version 2.1, 3.0 and 4.0 are found.
22 * If the VCARD doesn't know its version, 4.0 is assumed.
24 const DEFAULT_VERSION = '4.0';
27 * Validates the node for correctness.
29 * The following options are supported:
30 * - Component::REPAIR - If something is broken, and automatic repair may
33 * An array is returned with warnings.
35 * Every item in the array has the following properties:
36 * * level - (number between 1 and 3 with severity information)
37 * * message - (human readable message)
38 * * node - (reference to the offending node)
43 public function validate($options = 0) {
47 $version = $this->select('VERSION');
48 if (count($version)!==1) {
51 'message' => 'The VERSION property must appear in the VCARD component exactly 1 time',
54 if ($options & self::REPAIR) {
55 $this->VERSION = self::DEFAULT_VERSION;
58 $version = (string)$this->VERSION;
59 if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') {
62 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
65 if ($options & self::REPAIR) {
66 $this->VERSION = '4.0';
71 $version = $this->select('FN');
72 if (count($version)!==1) {
75 'message' => 'The FN property must appear in the VCARD component exactly 1 time',
78 if (($options & self::REPAIR) && count($version) === 0) {
79 // We're going to try to see if we can use the contents of the
81 if (isset($this->N)) {
82 $value = explode(';', (string)$this->N);
83 if (isset($value[1]) && $value[1]) {
84 $this->FN = $value[1] . ' ' . $value[0];
86 $this->FN = $value[0];
89 // Otherwise, the ORG property may work
90 } elseif (isset($this->ORG)) {
91 $this->FN = (string)$this->ORG;
98 parent::validate($options),