1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sylius\ShopApiPlugin\Model; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Webmozart\Assert\Assert; |
9
|
|
|
|
10
|
|
|
final class Address |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $firstName; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $lastName; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $city; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $countryCode; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $street; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $postcode; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $provinceName; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private $provinceCode; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $company; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
private $phoneNumber; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $firstName |
64
|
|
|
* @param string $lastName |
65
|
|
|
* @param string $city |
66
|
|
|
* @param string $street |
67
|
|
|
* @param string $countryCode |
68
|
|
|
* @param string $postcode |
69
|
|
|
* @param string $provinceName |
70
|
|
|
* @param string $provinceCode |
71
|
|
|
* @param string $company |
72
|
|
|
* @param string $phoneNumber |
73
|
|
|
*/ |
74
|
|
|
private function __construct( |
75
|
|
|
$firstName, |
76
|
|
|
$lastName, |
77
|
|
|
$city, |
78
|
|
|
$street, |
79
|
|
|
$countryCode, |
80
|
|
|
$postcode, |
81
|
|
|
$provinceName = null, |
82
|
|
|
$provinceCode = null, |
83
|
|
|
$phoneNumber = null, |
84
|
|
|
$company = null |
85
|
|
|
) { |
86
|
|
|
$this->firstName = $firstName; |
87
|
|
|
$this->lastName = $lastName; |
88
|
|
|
$this->city = $city; |
89
|
|
|
$this->street = $street; |
90
|
|
|
$this->countryCode = $countryCode; |
91
|
|
|
$this->postcode = $postcode; |
92
|
|
|
$this->provinceName = $provinceName; |
93
|
|
|
$this->provinceCode = $provinceCode; |
94
|
|
|
$this->phoneNumber = $phoneNumber; |
95
|
|
|
$this->company = $company; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param array $address |
100
|
|
|
* |
101
|
|
|
* @return Address |
102
|
|
|
*/ |
103
|
|
|
public static function createFromArray(array $address): self |
104
|
|
|
{ |
105
|
|
|
Assert::keyExists($address, 'firstName'); |
106
|
|
|
Assert::keyExists($address, 'lastName'); |
107
|
|
|
Assert::keyExists($address, 'city'); |
108
|
|
|
Assert::keyExists($address, 'street'); |
109
|
|
|
Assert::keyExists($address, 'countryCode'); |
110
|
|
|
Assert::keyExists($address, 'postcode'); |
111
|
|
|
|
112
|
|
|
return new self( |
113
|
|
|
$address['firstName'], |
114
|
|
|
$address['lastName'], |
115
|
|
|
$address['city'], |
116
|
|
|
$address['street'], |
117
|
|
|
$address['countryCode'], |
118
|
|
|
$address['postcode'], |
119
|
|
|
$address['provinceName'] ?? null, |
120
|
|
|
$address['provinceCode'] ?? null, |
121
|
|
|
$address['phoneNumber'] ?? null, |
122
|
|
|
$address['company'] ?? null |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param Request $request |
128
|
|
|
* |
129
|
|
|
* @return Address |
130
|
|
|
*/ |
131
|
|
|
public static function createFromRequest(Request $request): self |
132
|
|
|
{ |
133
|
|
|
return new self( |
134
|
|
|
$request->request->get('firstName'), |
135
|
|
|
$request->request->get('lastName'), |
136
|
|
|
$request->request->get('city'), |
137
|
|
|
$request->request->get('street'), |
138
|
|
|
$request->request->get('countryCode'), |
139
|
|
|
$request->request->get('postcode'), |
140
|
|
|
$request->request->get('provinceName'), |
141
|
|
|
$request->request->get('provinceCode'), |
142
|
|
|
$request->request->get('phoneNumber'), |
143
|
|
|
$request->request->get('company') |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function firstName() |
151
|
|
|
{ |
152
|
|
|
return $this->firstName; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function lastName() |
159
|
|
|
{ |
160
|
|
|
return $this->lastName; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function city() |
167
|
|
|
{ |
168
|
|
|
return $this->city; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function street() |
175
|
|
|
{ |
176
|
|
|
return $this->street; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string |
181
|
|
|
*/ |
182
|
|
|
public function countryCode() |
183
|
|
|
{ |
184
|
|
|
return $this->countryCode; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return string |
189
|
|
|
*/ |
190
|
|
|
public function postcode() |
191
|
|
|
{ |
192
|
|
|
return $this->postcode; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return string |
197
|
|
|
*/ |
198
|
|
|
public function provinceName() |
199
|
|
|
{ |
200
|
|
|
return $this->provinceName; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
public function provinceCode() |
207
|
|
|
{ |
208
|
|
|
return $this->provinceCode; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
public function company() |
215
|
|
|
{ |
216
|
|
|
return $this->company; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function phoneNumber() |
223
|
|
|
{ |
224
|
|
|
return $this->phoneNumber; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|