1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smoren\EventRouter\Events; |
4
|
|
|
|
5
|
|
|
use Smoren\EventRouter\Interfaces\EventInterface; |
6
|
|
|
use Smoren\EventRouter\Interfaces\EventLinkInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* LinkedEvent class |
10
|
|
|
*/ |
11
|
|
|
class LinkedEvent implements EventInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string origin |
15
|
|
|
*/ |
16
|
|
|
protected string $origin; |
17
|
|
|
/** |
18
|
|
|
* @var string name |
19
|
|
|
*/ |
20
|
|
|
protected string $name; |
21
|
|
|
/** |
22
|
|
|
* @var array<mixed> recipients |
23
|
|
|
*/ |
24
|
|
|
protected array $recipients; |
25
|
|
|
/** |
26
|
|
|
* @var EventLinkInterface link |
27
|
|
|
*/ |
28
|
|
|
protected EventLinkInterface $link; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* LinkedEvent constructor |
32
|
|
|
* @param string $origin |
33
|
|
|
* @param string $name |
34
|
|
|
* @param EventLinkInterface $link |
35
|
|
|
* @param string[] $recipients |
36
|
|
|
*/ |
37
|
12 |
|
public function __construct(string $origin, string $name, EventLinkInterface $link, array $recipients = []) |
38
|
|
|
{ |
39
|
12 |
|
$this->origin = $origin; |
40
|
12 |
|
$this->name = $name; |
41
|
12 |
|
$this->recipients = array_values($recipients); |
42
|
12 |
|
$this->link = $link; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritDoc} |
47
|
|
|
*/ |
48
|
12 |
|
public function getOrigin(): string |
49
|
|
|
{ |
50
|
12 |
|
return $this->origin; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
12 |
|
public function getName(): string |
57
|
|
|
{ |
58
|
12 |
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
2 |
|
public function getRecipients(): array |
65
|
|
|
{ |
66
|
2 |
|
return $this->recipients; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
2 |
|
public function getData(): array |
73
|
|
|
{ |
74
|
2 |
|
return $this->link->getData(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function getLink(): EventLinkInterface |
81
|
|
|
{ |
82
|
1 |
|
return $this->link; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function toArray(): array |
89
|
|
|
{ |
90
|
1 |
|
return [ |
91
|
1 |
|
'origin' => $this->getOrigin(), |
92
|
1 |
|
'name' => $this->getName(), |
93
|
1 |
|
'recipients' => $this->getRecipients(), |
94
|
1 |
|
'data' => $this->getData(), |
95
|
1 |
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|