/** * @return VCardEmail|null */ public static function createFromAttribute(VCardElementAttribute $attr) { $types = array_map('strtoupper', $attr->getParamValues('TYPE')); $typeMap = array_flip($types); if (isset($typeMap['x400'])) { // X.400 is not supported return null; } $item = new VCardEmail(); $item->value = $attr->getValue(); $item->types = $types; return $item; }
/** * @return VCardPhone|null */ public static function createFromAttribute(VCardElementAttribute $attr) { $item = new VCardPhone(); $item->value = $attr->getValue(); $item->valueType = strtoupper($attr->getFirstParamValue('VALUE', 'text')); $item->types = array_map('strtoupper', $attr->getParamValues('TYPE')); return $item; }
/** * @return VCardAddress|null */ public static function createFromAttribute(VCardElementAttribute $attr) { $str = $attr->getValue(); $parts = explode(';', $str); if (count($parts) < 7) { return null; } $item = new VCardAddress(); for ($i = 0; $i < 7; $i++) { $s = trim($parts[$i]); if ($s === '') { continue; } if ($i === 0) { $item->pobox = $s; } elseif ($i === 1) { $item->ext = $s; } elseif ($i === 2) { $item->street = $s; } elseif ($i === 3) { $item->locality = $s; } elseif ($i === 4) { $item->region = $s; } elseif ($i === 5) { $item->code = $s; } elseif ($i === 6) { $item->country = $s; } } return $item; }
/** * @return VCardFile|null */ public static function createFromAttribute(VCardElementAttribute $attr) { $item = new VCardFile(); $item->value = $attr->getValue(); $item->valueType = strtoupper($attr->getFirstParamValue('VALUE', '')); $item->type = strtoupper($attr->getFirstParamValue('TYPE', '')); $item->encoding = strtoupper($attr->getFirstParamValue('ENCODING', '')); return $item; }
/** * @return VCardElement */ public static function parseFromArray(array $array) { $attributes = array(); $qty = count($array); $s = ''; for ($i = $qty - 1; $i >= 0; $i--) { if ($s === '') { $s = $array[$i]; } else { //Try to parse multiline attribute $s = $array[$i] . PHP_EOL . $s; } if (!VCardElementAttribute::isValidAttributeString($s)) { continue; } $attr = VCardElementAttribute::parseFromString($s); if ($attr !== null) { $name = $attr->getName(); if (!isset($attributes[$name])) { $attributes[$name] = array(); } array_unshift($attributes[$name], $attr); } $s = ''; } return new VCardElement(array_reverse($attributes)); }