1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* LibreDTE: Biblioteca PHP (Núcleo). |
7
|
|
|
* Copyright (C) LibreDTE <https://www.libredte.cl> |
8
|
|
|
* |
9
|
|
|
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo |
10
|
|
|
* bajo los términos de la Licencia Pública General Affero de GNU publicada por |
11
|
|
|
* la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o |
12
|
|
|
* (a su elección) cualquier versión posterior de la misma. |
13
|
|
|
* |
14
|
|
|
* Este programa se distribuye con la esperanza de que sea útil, pero SIN |
15
|
|
|
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD |
16
|
|
|
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública |
17
|
|
|
* General Affero de GNU para obtener una información más detallada. |
18
|
|
|
* |
19
|
|
|
* Debería haber recibido una copia de la Licencia Pública General Affero de |
20
|
|
|
* GNU junto a este programa. |
21
|
|
|
* |
22
|
|
|
* En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace libredte\lib\Core\Package\Billing\Component\Exchange\Abstract; |
26
|
|
|
|
27
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\PartyEndpointInterface; |
28
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\PartyIdentifierInterface; |
29
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\PartyInterface; |
30
|
|
|
use Symfony\Component\Mime\Address; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Clase base para los participantes del intercambio de documentos. |
34
|
|
|
*/ |
35
|
|
|
abstract class AbstractParty implements PartyInterface |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Identificador único del participante. |
39
|
|
|
* |
40
|
|
|
* @var PartyIdentifierInterface |
41
|
|
|
*/ |
42
|
|
|
private PartyIdentifierInterface $identifier; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Listado de puntos de recepción de documentos del participante. |
46
|
|
|
* |
47
|
|
|
* @var PartyEndpointInterface[] |
48
|
|
|
*/ |
49
|
|
|
private array $endpoints; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Constructor del participante. |
53
|
|
|
* |
54
|
|
|
* @param PartyIdentifierInterface $identifier |
55
|
|
|
* @param PartyEndpointInterface[] $endpoints |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
PartyIdentifierInterface $identifier, |
59
|
|
|
array $endpoints = [] |
60
|
|
|
) { |
61
|
|
|
$this->identifier = $identifier; |
62
|
|
|
$this->endpoints = $endpoints; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritDoc} |
67
|
|
|
*/ |
68
|
|
|
public function getIdentifier(): PartyIdentifierInterface |
69
|
|
|
{ |
70
|
|
|
return $this->identifier; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
public function addEndpoint(PartyEndpointInterface $endpoint): static |
77
|
|
|
{ |
78
|
|
|
$this->endpoints[] = $endpoint; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritDoc} |
85
|
|
|
*/ |
86
|
|
|
public function getEndpoints(): array |
87
|
|
|
{ |
88
|
|
|
return $this->endpoints; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
|
|
public function getEmails(): array |
95
|
|
|
{ |
96
|
|
|
$emails = []; |
97
|
|
|
|
98
|
|
|
foreach ($this->endpoints as $endpoint) { |
99
|
|
|
if ($endpoint->getSchemeId() === 'EMAIL') { |
100
|
|
|
$aux = explode(':', $endpoint->getValue(), 2); |
101
|
|
|
$emails[] = new Address($aux[0], $aux[1] ?? ''); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $emails; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|