1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sylius\ShopApiPlugin\Model; |
4
|
|
|
|
5
|
|
|
use Webmozart\Assert\Assert; |
6
|
|
|
|
7
|
|
|
final class Address |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
private $firstName; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $lastName; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $city; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $countryCode; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $street; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $postcode; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $provinceName; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $firstName |
46
|
|
|
* @param string $lastName |
47
|
|
|
* @param string $city |
48
|
|
|
* @param string $street |
49
|
|
|
* @param string $countryCode |
50
|
|
|
* @param string $postcode |
51
|
|
|
* @param string $provinceName |
52
|
|
|
*/ |
53
|
|
|
private function __construct($firstName, $lastName, $city, $street, $countryCode, $postcode, $provinceName = null) |
54
|
|
|
{ |
55
|
|
|
$this->firstName = $firstName; |
56
|
|
|
$this->lastName = $lastName; |
57
|
|
|
$this->city = $city; |
58
|
|
|
$this->street = $street; |
59
|
|
|
$this->countryCode = $countryCode; |
60
|
|
|
$this->postcode = $postcode; |
61
|
|
|
$this->provinceName = $provinceName; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param array $address |
66
|
|
|
* |
67
|
|
|
* @return Address |
68
|
|
|
*/ |
69
|
|
|
public static function createFromArray(array $address) |
70
|
|
|
{ |
71
|
|
|
Assert::keyExists($address, 'firstName'); |
72
|
|
|
Assert::keyExists($address, 'lastName'); |
73
|
|
|
Assert::keyExists($address, 'city'); |
74
|
|
|
Assert::keyExists($address, 'street'); |
75
|
|
|
Assert::keyExists($address, 'countryCode'); |
76
|
|
|
Assert::keyExists($address, 'postcode'); |
77
|
|
|
|
78
|
|
|
return new Address( |
79
|
|
|
$address['firstName'], |
80
|
|
|
$address['lastName'], |
81
|
|
|
$address['city'], |
82
|
|
|
$address['street'], |
83
|
|
|
$address['countryCode'], |
84
|
|
|
$address['postcode'], |
85
|
|
|
isset($address['provinceName']) ? $address['provinceName'] : null |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function firstName() |
93
|
|
|
{ |
94
|
|
|
return $this->firstName; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function lastName() |
101
|
|
|
{ |
102
|
|
|
return $this->lastName; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function city() |
109
|
|
|
{ |
110
|
|
|
return $this->city; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function street() |
117
|
|
|
{ |
118
|
|
|
return $this->street; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function countryCode() |
125
|
|
|
{ |
126
|
|
|
return $this->countryCode; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function postcode() |
133
|
|
|
{ |
134
|
|
|
return $this->postcode; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function provinceName() |
141
|
|
|
{ |
142
|
|
|
return $this->provinceName; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|