blob: 9145bb21f639c355c4b199419f60f562957a0914 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?php
namespace SRF\vCard;
/**
* Represents a single address entry in an vCard
*
* @see http://www.semantic-mediawiki.org/wiki/vCard
*
* @license GNU GPL v2+
* @since 1.5
*
* @author Markus Krötzsch
* @author Denny Vrandecic
* @author Frank Dengler
*/
class Address {
/**
* @var string
*/
private $type;
/**
* @var array
*/
private $adr = [];
/**
* @param string $type
* @param array $adr
*/
public function __construct( $type, array $adr = [] ) {
$this->type = $type;
$this->adr = $adr;
}
/**
* @since 3.1
*
* @return boolean
*/
public function hasAddress() {
return $this->adr !== [];
}
/**
* @since 3.1
*
* @param string $key
* @param string $value
*/
public function set( $key, $value ) {
$this->adr[$key] = $value;
}
/**
* @return string
*/
public function text() {
if ( $this->type == "" ) {
$this->type = "WORK";
}
$adr = [];
// Expected sequence as defined by
// https://tools.ietf.org/html/rfc6350#section-6.3.1
$map = [
'pobox',
'ext',
'street',
'locality',
'region',
'code',
'country'
];
foreach ( $map as $k ) {
$adr[] = isset( $this->adr[$k] ) ? vCard::escape( $this->adr[$k] ) : '';
}
return "ADR;TYPE=$this->type;CHARSET=UTF-8:" . implode( ';', $adr ) . "\r\n";
}
}
|