forked from jeroendesloovere/vcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddress.php
141 lines (115 loc) · 3.5 KB
/
Address.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
declare(strict_types=1);
namespace JeroenDesloovere\VCard\Property;
use JeroenDesloovere\VCard\Exception\PropertyException;
use JeroenDesloovere\VCard\Formatter\Property\AddressFormatter;
use JeroenDesloovere\VCard\Formatter\Property\NodeFormatterInterface;
use JeroenDesloovere\VCard\Parser\Property\AddressParser;
use JeroenDesloovere\VCard\Parser\Property\NodeParserInterface;
use JeroenDesloovere\VCard\Property\Parameter\Type;
final class Address implements PropertyInterface, NodeInterface
{
/** @var null|string */
private $postOfficeBox;
/** @var null|string - e.g.: apartment or suite number */
private $extendedAddress;
/** @var null|string */
private $streetAddress;
/** @var null|string - e.g.: city */
private $locality;
/** @var null|string - e.g.: state or province */
private $region;
/** @var null|string */
private $postalCode;
/** @var null|string - The country name in your own language, e.g.: belgië */
private $countryName;
/** @var Type */
private $type;
/**
* @param null|string $postOfficeBox
* @param null|string $extendedAddress
* @param null|string $streetAddress
* @param null|string $locality
* @param null|string $region
* @param null|string $postalCode
* @param null|string $countryName
* @param Type|null $type
* @throws PropertyException
*/
public function __construct(
?string $postOfficeBox = null,
?string $extendedAddress = null,
?string $streetAddress = null,
?string $locality = null,
?string $region = null,
?string $postalCode = null,
?string $countryName = null,
Type $type = null
) {
if ($postOfficeBox === null && $extendedAddress === null && $streetAddress === null && $locality === null
&& $region === null && $postalCode === null && $countryName === null && $type === null
) {
throw PropertyException::forEmptyProperty();
}
$this->postOfficeBox = $postOfficeBox;
$this->extendedAddress = $extendedAddress;
$this->streetAddress = $streetAddress;
$this->locality = $locality;
$this->region = $region;
$this->postalCode = $postalCode;
$this->countryName = $countryName;
$this->type = $type ?? Type::home();
}
public function getFormatter(): NodeFormatterInterface
{
return new AddressFormatter($this);
}
public static function getNode(): string
{
return 'ADR';
}
public static function getParser(): NodeParserInterface
{
return new AddressParser();
}
public function isAllowedMultipleTimes(): bool
{
return true;
}
public function getPostOfficeBox(): ?string
{
return $this->postOfficeBox;
}
public function getExtendedAddress(): ?string
{
return $this->extendedAddress;
}
public function getStreetAddress(): ?string
{
return $this->streetAddress;
}
public function getLocality(): ?string
{
return $this->locality;
}
public function getRegion(): ?string
{
return $this->region;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function getCountryName(): ?string
{
return $this->countryName;
}
public function getType(): Type
{
return $this->type;
}
public function setType(Type $type)
{
$this->type = $type;
}
}