-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddress.php
executable file
·330 lines (262 loc) · 5.31 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php declare(strict_types=1);
namespace DhlMyApi;
class Address
{
/* @var string */
protected $street;
/* @var string */
protected $zipCode;
/* @var string */
protected $city;
/* @var string */
protected $country;
/* @var string */
protected $name;
/* @var string */
protected $name2;
/* @var string */
protected $email;
/* @var string */
protected $phone;
/* @var string */
protected $contact;
const COUNTRIES = [
'CZ', // Česká republika
'DE', // Nemecko
'GB', // Anglicko
'SK', // Slovensko
'AT', // Rakúsko
'PL', // Poľsko
'CH', // Švajčiarsko
'FI', // Fínsko
'HU', // Maďarsko
'SI', // Slovinsko
'LV', // Lotyšsko
'EE', // Estonsko
'LT', // Litva
'BE', // Belgicko
'DK', // Dánsko
'ES', // Španielsko
'FR', // Francúzsko
'IE', // Írsko
'IT', // Taliansko
'NL', // Holandsko
'NO', // Nórsko
'PT', // Portugalsko
'SE', // Švédsko
'RO', // Rumunsko
'BG', // Bulharsko
'GR', // Grácko
'RU', // Rusko
'TR', // Turecko
'LU', // Luxembursko
'HR', // Chorvátsko
];
const COUNTRY_CZ = 'CZ'; // Česká republika
const COUNTRY_DE = 'DE'; // Nemecko
const COUNTRY_GB = 'GB'; // Anglicko
const COUNTRY_SK = 'SK'; // Slovensko
const COUNTRY_AT = 'AT'; // Rakúsko
const COUNTRY_PL = 'PL'; // Poľsko
const COUNTRY_CH = 'CH'; // Švajčiarsko
const COUNTRY_FI = 'FI'; // Fínsko
const COUNTRY_HU = 'HU'; // Maďarsko
const COUNTRY_SI = 'SI'; // Slovinsko
const COUNTRY_LV = 'LV'; // Lotyšsko
const COUNTRY_EE = 'EE'; // Estonsko
const COUNTRY_LT = 'LT'; // Litva
const COUNTRY_BE = 'BE'; // Belgicko
const COUNTRY_DK = 'DK'; // Dánsko
const COUNTRY_ES = 'ES'; // Španielsko
const COUNTRY_FR = 'FR'; // Francúzsko
const COUNTRY_IE = 'IE'; // Írsko
const COUNTRY_IT = 'IT'; // Taliansko
const COUNTRY_NL = 'NL'; // Holandsko
const COUNTRY_NO = 'NO'; // Nórsko
const COUNTRY_PT = 'PT'; // Portugalsko
const COUNTRY_SE = 'SE'; // Švédsko
const COUNTRY_RO = 'RO'; // Rumunsko
const COUNTRY_BG = 'BG'; // Bulharsko
const COUNTRY_GR = 'GR'; // Grácko
const COUNTRY_RU = 'RU'; // Rusko
const COUNTRY_TR = 'TR'; // Turecko
const COUNTRY_LU = 'LU'; // Luxembursko
const COUNTRY_HR = 'HR'; // Chorvátsko
/**
* @param string
* @param string
* @param string
* @param string
* @param string
* @param string
* @param string
* @param string
* @param string
*/
public function __construct(string $name, string $street, string $zipCode, string $city, string $country = NULL)
{
$this->setName($name);
$this->setStreet($street);
$this->setZipCode($zipCode);
$this->setCity($city);
if ($country !== NULL) {
$this->setCountry($country);
}
}
/**
* @param string
* @return self
*/
public function setStreet(string $value): Address
{
$this->street = mb_substr($value, 0, 50);
return $this;
}
/**
* @return string
*/
public function getStreet(): string
{
return $this->street;
}
/**
* @param string
* @return self
*/
public function setZipCode(string $value): Address
{
$this->zipCode = mb_substr($value, 0, 10);
return $this;
}
/**
* @return string
*/
public function getZipCode(): string
{
return $this->zipCode;
}
/**
* @param string
* @return self
*/
public function setCity(string $value): Address
{
$this->city = mb_substr($value, 0, 50);
return $this;
}
/**
* @return string
*/
public function getCity(): string
{
return $this->city;
}
/**
* @param string
* @return self
* @throws \Exception
*/
public function setCountry(string $value): Address
{
$code = strtoupper($value);
if (in_array($code, self::COUNTRIES)) {
$this->country = $code;
} else {
throw new \Exception("Country '" . $value . "' not found");
}
return $this;
}
/**
* @return string
*/
public function getCountry(): ?string
{
return $this->country;
}
/**
* @param string
* @return self
*/
public function setName(string $value): Address
{
$this->name = mb_substr($value, 0, 50);
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string
* @return self
*/
public function setName2(string $value): Address
{
$this->name2 = mb_substr($value, 0, 50);
return $this;
}
/**
* @return string
*/
public function getName2(): ?string
{
return $this->name2;
}
/**
* @param string
* @return self
* @throws \Exception
*/
public function setEmail(string $value): Address
{
$email = mb_substr($value, 0, 50);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->email = $email;
} else {
throw new \Exception("E-mail '" . $email . "' has invalid format");
}
return $this;
}
/**
* @return string
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param string
* @return self
*/
public function setPhone(string $value): Address
{
$this->phone = mb_substr($value, 0, 30);
return $this;
}
/**
* @return string
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string
* @return self
*/
public function setContact(string $value): Address
{
$this->contact = mb_substr($value, 0, 300);
return $this;
}
/**
* @return string
*/
public function getContact(): ?string
{
return $this->contact;
}
}