|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Domain\Common\Model\VO; |
|
15
|
|
|
|
|
16
|
|
|
final class ContactAddress |
|
17
|
|
|
{ |
|
18
|
|
|
private string $address; |
|
19
|
|
|
private string $zipCode; |
|
20
|
|
|
private string $town; |
|
21
|
|
|
private string $country; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(string $address, string $zipCode, string $town, string $country) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->address = $address; |
|
26
|
|
|
$this->zipCode = $zipCode; |
|
27
|
|
|
$this->town = $town; |
|
28
|
|
|
$this->country = $country; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public static function fromString(string $stringAddress): self |
|
32
|
|
|
{ |
|
33
|
|
|
\preg_match( |
|
34
|
|
|
'/([0-9-a-zA-Zéêèëùûü ]*)\n(\d{5}) ([0-9-a-zA-Zéêèëùûü ]*), ([0-9-a-zA-Zéêèëùûü ]*)/u', |
|
35
|
|
|
$stringAddress, |
|
36
|
|
|
$completeAddress |
|
37
|
|
|
); |
|
38
|
|
|
[$full, $address, $zipCode, $town, $country] = $completeAddress; |
|
39
|
|
|
|
|
40
|
|
|
return new self($address, $zipCode, $town, $country); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public static function fromArray(array $addressData): self |
|
44
|
|
|
{ |
|
45
|
|
|
if ([$address, $zipcode, $town, $country] = $addressData) { |
|
46
|
|
|
return new self($address, $zipcode, $town, $country); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
throw new \DomainException('The address data are not valid'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getValue(): string |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->address . "\n" . $this->zipCode . ' ' . $this->town . ', ' . $this->country; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function address(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->address; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function zipCode(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->zipCode; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function town(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->town; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function country(): string |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->country; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|