|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
6
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Contact\ContactPoint as Udb3ModelContactPoint; |
|
7
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumber; |
|
8
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddress; |
|
9
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Web\Url; |
|
10
|
|
|
|
|
11
|
|
|
final class ContactPoint implements SerializableInterface, JsonLdSerializableInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $phones = array(); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $emails = array(); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $urls = array(); |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(array $phones = [], array $emails = [], array $urls = []) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->phones = $phones; |
|
31
|
|
|
$this->emails = $emails; |
|
32
|
|
|
$this->urls = $urls; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getPhones(): array |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->phones; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getEmails(): array |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->emails; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getUrls(): array |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->urls; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function serialize(): array |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
'phone' => $this->phones, |
|
54
|
|
|
'email' => $this->emails, |
|
55
|
|
|
'url' => $this->urls, |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function deserialize(array $data): ContactPoint |
|
60
|
|
|
{ |
|
61
|
|
|
return new self($data['phone'], $data['email'], $data['url']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function toJsonLd(): array |
|
65
|
|
|
{ |
|
66
|
|
|
// Serialized version is the same. |
|
67
|
|
|
return $this->serialize(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function sameAs(ContactPoint $otherContactPoint): bool |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->toJsonLd() === $otherContactPoint->toJsonLd(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function fromUdb3ModelContactPoint(Udb3ModelContactPoint $contactPoint): ContactPoint |
|
76
|
|
|
{ |
|
77
|
|
|
$phones = array_map( |
|
78
|
|
|
function (TelephoneNumber $phone) { |
|
79
|
|
|
return $phone->toString(); |
|
80
|
|
|
}, |
|
81
|
|
|
$contactPoint->getTelephoneNumbers()->toArray() |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$emails = array_map( |
|
85
|
|
|
function (EmailAddress $emailAddress) { |
|
86
|
|
|
return $emailAddress->toString(); |
|
87
|
|
|
}, |
|
88
|
|
|
$contactPoint->getEmailAddresses()->toArray() |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$urls = array_map( |
|
92
|
|
|
function (Url $url) { |
|
93
|
|
|
return $url->toString(); |
|
94
|
|
|
}, |
|
95
|
|
|
$contactPoint->getUrls()->toArray() |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
return new self($phones, $emails, $urls); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|