1
|
|
|
<?php namespace Ups\Entity\AddressValidation; |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class AVAddress |
5
|
|
|
{ |
6
|
|
|
public $addressClassification; |
7
|
|
|
public $consigneeName; |
8
|
|
|
public $buildingName; |
9
|
|
|
public $addressLine; |
10
|
|
|
public $region; |
11
|
|
|
public $politicalDivision2; |
12
|
|
|
public $politicalDivision1; |
13
|
|
|
public $postcodePrimaryLow; |
14
|
|
|
public $postcodeExtendedLow; |
15
|
|
|
public $urbanization; |
16
|
|
|
public $countryCode; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Address constructor. |
20
|
|
|
* @param \SimpleXMLElement $xmlDoc |
21
|
|
|
*/ |
22
|
2 |
|
public function __construct(\SimpleXMLElement $xmlDoc) |
23
|
|
|
{ |
24
|
2 |
|
if ($xmlDoc->count() == 0) { |
25
|
|
|
throw new \InvalidArgumentException(__METHOD__ . ': The passed object does not have any child nodes.'); |
26
|
|
|
} |
27
|
2 |
|
$this->addressClassification = isset($xmlDoc->AddressClassification) ? new AddressClassification($xmlDoc->AddressClassification) : null; |
28
|
2 |
|
$this->consigneeName = isset($xmlDoc->ConsigneeName) ? (string)$xmlDoc->ConsigneeName : ''; |
29
|
2 |
|
$this->buildingName = isset($xmlDoc->BuildingName) ? (string)$xmlDoc->BuildingName : ''; |
30
|
2 |
|
$this->addressLine = isset($xmlDoc->AddressLine) ? (string)$xmlDoc->AddressLine : ''; |
31
|
2 |
|
$this->region = isset($xmlDoc->Region) ? (string)$xmlDoc->Regions : ''; |
32
|
2 |
|
$this->politicalDivision2 = isset($xmlDoc->PoliticalDivision2) ? (string)$xmlDoc->PoliticalDivision2 : ''; |
33
|
2 |
|
$this->politicalDivision1 = isset($xmlDoc->PoliticalDivision1) ? (string)$xmlDoc->PoliticalDivision1 : ''; |
34
|
2 |
|
$this->postcodePrimaryLow = isset($xmlDoc->PostcodePrimaryLow) ? (string)$xmlDoc->PostcodePrimaryLow : ''; |
35
|
2 |
|
$this->postcodeExtendedLow = isset($xmlDoc->PostcodeExtendedLow) ? (string)$xmlDoc->PostcodeExtendedLow : ''; |
36
|
2 |
|
$this->urbanization = isset($xmlDoc->Urbanization) ? (string)$xmlDoc->Urbanization : ''; |
37
|
2 |
|
$this->consigneeName = isset($xmlDoc->CountryCode) ? (string)$xmlDoc->CountryCode : ''; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Convenience methods. Even though all properties are public, these methods provide a convenient interface to |
42
|
|
|
* retrieve commonly requested parts so that the user doesn't have to remember which API fields reference |
43
|
|
|
* which piece of information. For example, I won't have to remember that the city is in 'PoliticalDivision2'. |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
1 |
|
public function getCity() |
50
|
|
|
{ |
51
|
1 |
|
return $this->politicalDivision2; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
1 |
|
public function getStateProvince() |
58
|
|
|
{ |
59
|
1 |
|
return $this->politicalDivision1; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param bool $withExtended |
64
|
|
|
* @param string $extendedDivider |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
1 |
|
public function getPostalCode($withExtended = false,$extendedDivider = '-') |
|
|
|
|
68
|
|
|
{ |
69
|
1 |
|
if($withExtended) { |
|
|
|
|
70
|
1 |
|
return $this->postcodePrimaryLow . $extendedDivider . $this->postcodeExtendedLow; |
71
|
|
|
} |
72
|
1 |
|
return $this->postcodePrimaryLow; |
73
|
|
|
} |
74
|
|
|
} |