1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Geo\HasAddressEmbeddableInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Geo\AddressEmbeddableInterface; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
12
|
|
|
|
13
|
|
|
class AddressEmbeddable extends AbstractEmbeddableObject implements AddressEmbeddableInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $houseNumber; |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $houseName; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $street; |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $city; |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $countryCode; |
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $postalCode; |
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $postalArea; |
43
|
|
|
|
44
|
2 |
|
public function __construct( |
45
|
|
|
string $houseNumber, |
46
|
|
|
string $houseName, |
47
|
|
|
string $street, |
48
|
|
|
string $city, |
49
|
|
|
string $postalArea, |
50
|
|
|
string $postalCode, |
51
|
|
|
string $countryCode |
52
|
|
|
) { |
53
|
2 |
|
$this->setHouseNumber($houseNumber); |
54
|
2 |
|
$this->setHouseName($houseName); |
55
|
2 |
|
$this->setStreet($street); |
56
|
2 |
|
$this->setCity($city); |
57
|
2 |
|
$this->setPostalArea($postalArea); |
58
|
2 |
|
$this->setPostalCode($postalCode); |
59
|
2 |
|
$this->setCountryCode($countryCode); |
60
|
2 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $houseNumber |
64
|
|
|
* |
65
|
|
|
* @return AddressEmbeddable |
66
|
|
|
*/ |
67
|
2 |
|
private function setHouseNumber(string $houseNumber): AddressEmbeddableInterface |
68
|
|
|
{ |
69
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
70
|
2 |
|
'houseNumber', |
71
|
2 |
|
$this->houseNumber, |
72
|
2 |
|
$houseNumber |
73
|
|
|
); |
74
|
2 |
|
$this->houseNumber = $houseNumber; |
75
|
|
|
|
76
|
2 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $houseName |
81
|
|
|
* |
82
|
|
|
* @return AddressEmbeddable |
83
|
|
|
*/ |
84
|
2 |
|
private function setHouseName(string $houseName): AddressEmbeddableInterface |
85
|
|
|
{ |
86
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
87
|
2 |
|
'houseName', |
88
|
2 |
|
$this->houseName, |
89
|
2 |
|
$houseName |
90
|
|
|
); |
91
|
2 |
|
$this->houseName = $houseName; |
92
|
|
|
|
93
|
2 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $street |
98
|
|
|
* |
99
|
|
|
* @return AddressEmbeddable |
100
|
|
|
*/ |
101
|
2 |
|
private function setStreet(string $street): AddressEmbeddableInterface |
102
|
|
|
{ |
103
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
104
|
2 |
|
'street', |
105
|
2 |
|
$this->street, |
106
|
2 |
|
$street |
107
|
|
|
); |
108
|
2 |
|
$this->street = $street; |
109
|
|
|
|
110
|
2 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $city |
115
|
|
|
* |
116
|
|
|
* @return AddressEmbeddable |
117
|
|
|
*/ |
118
|
2 |
|
private function setCity(string $city): AddressEmbeddableInterface |
119
|
|
|
{ |
120
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
121
|
2 |
|
'city', |
122
|
2 |
|
$this->city, |
123
|
2 |
|
$city |
124
|
|
|
); |
125
|
2 |
|
$this->city = $city; |
126
|
|
|
|
127
|
2 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $countryCode |
132
|
|
|
* |
133
|
|
|
* @return AddressEmbeddable |
134
|
|
|
*/ |
135
|
2 |
|
private function setCountryCode(string $countryCode): AddressEmbeddableInterface |
136
|
|
|
{ |
137
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
138
|
2 |
|
'countryCode', |
139
|
2 |
|
$this->countryCode, |
140
|
2 |
|
$countryCode |
141
|
|
|
); |
142
|
2 |
|
$this->countryCode = $countryCode; |
143
|
|
|
|
144
|
2 |
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $postalCode |
149
|
|
|
* |
150
|
|
|
* @return AddressEmbeddable |
151
|
|
|
*/ |
152
|
2 |
|
private function setPostalCode(string $postalCode): AddressEmbeddableInterface |
153
|
|
|
{ |
154
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
155
|
2 |
|
'postalCode', |
156
|
2 |
|
$this->postalCode, |
157
|
2 |
|
$postalCode |
158
|
|
|
); |
159
|
2 |
|
$this->postalCode = $postalCode; |
160
|
|
|
|
161
|
2 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $postalArea |
166
|
|
|
* |
167
|
|
|
* @return AddressEmbeddable |
168
|
|
|
*/ |
169
|
2 |
|
private function setPostalArea(string $postalArea): AddressEmbeddableInterface |
170
|
|
|
{ |
171
|
2 |
|
$this->notifyEmbeddablePrefixedProperties( |
172
|
2 |
|
'postalArea', |
173
|
2 |
|
$this->postalArea, |
174
|
2 |
|
$postalArea |
175
|
|
|
); |
176
|
2 |
|
$this->postalArea = $postalArea; |
177
|
|
|
|
178
|
2 |
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param ClassMetadata $metadata |
183
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
184
|
|
|
*/ |
185
|
|
|
public static function loadMetadata(ClassMetadata $metadata): void |
186
|
|
|
{ |
187
|
|
|
$builder = self::setEmbeddableAndGetBuilder($metadata); |
188
|
|
|
MappingHelper::setSimpleStringFields( |
189
|
|
|
[ |
190
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NUMBER, |
191
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NAME, |
192
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_STREET, |
193
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_CITY, |
194
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_AREA, |
195
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_CODE, |
196
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_COUNTRY_CODE, |
197
|
|
|
], |
198
|
|
|
$builder |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param array $properties |
204
|
|
|
* |
205
|
|
|
* @return AddressEmbeddableInterface |
206
|
|
|
*/ |
207
|
2 |
|
public static function create(array $properties): AddressEmbeddableInterface |
208
|
|
|
{ |
209
|
2 |
|
if (array_key_exists(AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NUMBER, $properties)) { |
210
|
2 |
|
return new self( |
211
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NUMBER], |
212
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NAME], |
213
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_STREET], |
214
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_CITY], |
215
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_AREA], |
216
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_CODE], |
217
|
2 |
|
$properties[AddressEmbeddableInterface::EMBEDDED_PROP_COUNTRY_CODE] |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
return new self(...array_values($properties)); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function __toString(): string |
225
|
|
|
{ |
226
|
|
|
return (string)print_r( |
227
|
|
|
[ |
228
|
|
|
'addressEmbeddable' => [ |
229
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NUMBER => $this->getHouseNumber(), |
230
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NAME => $this->getHouseName(), |
231
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_STREET => $this->getStreet(), |
232
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_CITY => $this->getCity(), |
233
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_AREA => $this->getPostalArea(), |
234
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_CODE => $this->getPostalCode(), |
235
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_COUNTRY_CODE => $this->getCountryCode(), |
236
|
|
|
], |
237
|
|
|
], |
238
|
|
|
true |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
2 |
|
public function getHouseNumber(): string |
246
|
|
|
{ |
247
|
2 |
|
return $this->houseNumber ?? ''; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
2 |
|
public function getHouseName(): string |
254
|
|
|
{ |
255
|
2 |
|
return $this->houseName ?? ''; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return string |
260
|
|
|
*/ |
261
|
2 |
|
public function getStreet(): string |
262
|
|
|
{ |
263
|
2 |
|
return $this->street ?? ''; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
2 |
|
public function getCity(): string |
270
|
|
|
{ |
271
|
2 |
|
return $this->city ?? ''; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return string |
276
|
|
|
*/ |
277
|
2 |
|
public function getPostalCode(): string |
278
|
|
|
{ |
279
|
2 |
|
return $this->postalCode ?? ''; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return string |
284
|
|
|
*/ |
285
|
2 |
|
public function getPostalArea(): string |
286
|
|
|
{ |
287
|
2 |
|
return $this->postalArea ?? ''; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return string |
292
|
|
|
*/ |
293
|
2 |
|
public function getCountryCode(): string |
294
|
|
|
{ |
295
|
2 |
|
return $this->countryCode ?? ''; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
protected function getPrefix(): string |
299
|
|
|
{ |
300
|
|
|
return HasAddressEmbeddableInterface::PROP_ADDRESS_EMBEDDABLE; |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|