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; |
26
|
|
|
|
27
|
|
|
use Derafu\Lib\Core\Foundation\Abstract\AbstractComponent; |
28
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\ExchangeBagInterface; |
29
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\ExchangeComponentInterface; |
30
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\ReceiverWorkerInterface; |
31
|
|
|
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\SenderWorkerInterface; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Componente "billing.exchange". |
35
|
|
|
*/ |
36
|
|
|
class ExchangeComponent extends AbstractComponent implements ExchangeComponentInterface |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Constructor del componente con sus dependencias. |
40
|
|
|
* |
41
|
|
|
* @param ReceiverWorkerInterface $receiverWorker |
42
|
|
|
* @param SenderWorkerInterface $senderWorker |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
private ReceiverWorkerInterface $receiverWorker, |
46
|
|
|
private SenderWorkerInterface $senderWorker |
47
|
|
|
) { |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
|
|
public function getWorkers(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'receiver' => $this->receiverWorker, |
57
|
|
|
'sender' => $this->senderWorker, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
|
|
public function getReceiverWorker(): ReceiverWorkerInterface |
65
|
|
|
{ |
66
|
|
|
return $this->receiverWorker; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function getSenderWorker(): SenderWorkerInterface |
73
|
|
|
{ |
74
|
|
|
return $this->senderWorker; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
|
|
public function receive(ExchangeBagInterface $bag): array |
81
|
|
|
{ |
82
|
|
|
return $this->receiverWorker->receive($bag); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
|
|
public function send(ExchangeBagInterface $bag): array |
89
|
|
|
{ |
90
|
|
|
return $this->senderWorker->send($bag); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritDoc} |
95
|
|
|
*/ |
96
|
|
|
public function handle(ExchangeBagInterface $bag): array |
97
|
|
|
{ |
98
|
|
|
if (!$bag->hasEnvelopes()) { |
99
|
|
|
return $this->receiverWorker->handle($bag); |
100
|
|
|
} else { |
101
|
|
|
return $this->senderWorker->handle($bag); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|