1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This class holds a structured representation of a postal address |
7
|
|
|
*/ |
8
|
|
|
class StructuredPostalAddress implements PostalAddressInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string|null |
12
|
|
|
*/ |
13
|
|
|
protected $street; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string|null |
17
|
|
|
*/ |
18
|
|
|
protected $buildingNo; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $postCode; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $town; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $country; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
* @param string|null $street Street name or null |
39
|
|
|
* @param string|null $buildingNo Building number or null |
40
|
|
|
* @param string $postCode Postal code |
41
|
|
|
* @param string $town Town name |
42
|
|
|
* @param string $country Country code (ISO 3166-1 alpha-2) |
43
|
|
|
*/ |
44
|
3 |
|
public function __construct($street, $buildingNo, $postCode, $town, $country = 'CH') |
45
|
|
|
{ |
46
|
3 |
|
$this->street = Text::assertOptional($street, 70); |
47
|
3 |
|
$this->buildingNo = Text::assertOptional($buildingNo, 16); |
48
|
3 |
|
$this->postCode = Text::assert($postCode, 16); |
49
|
3 |
|
$this->town = Text::assert($town, 35); |
50
|
3 |
|
$this->country = Text::assertCountryCode($country); |
51
|
3 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
2 |
|
public function asDom(\DOMDocument $doc) |
57
|
|
|
{ |
58
|
2 |
|
$root = $doc->createElement('PstlAdr'); |
59
|
|
|
|
60
|
2 |
|
if ($this->street !== null) { |
61
|
2 |
|
$root->appendChild(Text::xml($doc, 'StrtNm', $this->street)); |
62
|
2 |
|
} |
63
|
2 |
|
if ($this->buildingNo !== null) { |
64
|
2 |
|
$root->appendChild(Text::xml($doc, 'BldgNb', $this->buildingNo)); |
65
|
2 |
|
} |
66
|
2 |
|
$root->appendChild(Text::xml($doc, 'PstCd', $this->postCode)); |
67
|
2 |
|
$root->appendChild(Text::xml($doc, 'TwnNm', $this->town)); |
68
|
2 |
|
$root->appendChild(Text::xml($doc, 'Ctry', $this->country)); |
69
|
|
|
|
70
|
2 |
|
return $root; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|