1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Event; |
6
|
|
|
|
7
|
|
|
use Kerox\Messenger\Model\Callback\Referral; |
8
|
|
|
|
9
|
|
|
class ReferralEvent extends AbstractEvent |
10
|
|
|
{ |
11
|
|
|
public const NAME = 'referral'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var int |
15
|
|
|
*/ |
16
|
|
|
protected $timestamp; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Kerox\Messenger\Model\Callback\Referral |
20
|
|
|
*/ |
21
|
|
|
protected $referral; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ReferralEvent constructor. |
25
|
|
|
* |
26
|
|
|
* @param string $senderId |
27
|
|
|
* @param string $recipientId |
28
|
|
|
* @param int $timestamp |
29
|
|
|
* @param \Kerox\Messenger\Model\Callback\Referral $referral |
30
|
|
|
*/ |
31
|
2 |
|
public function __construct(string $senderId, string $recipientId, int $timestamp, Referral $referral) |
32
|
|
|
{ |
33
|
2 |
|
parent::__construct($senderId, $recipientId); |
34
|
|
|
|
35
|
2 |
|
$this->timestamp = $timestamp; |
36
|
2 |
|
$this->referral = $referral; |
37
|
2 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return int |
41
|
|
|
*/ |
42
|
1 |
|
public function getTimestamp(): int |
43
|
|
|
{ |
44
|
1 |
|
return $this->timestamp; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return \Kerox\Messenger\Model\Callback\Referral |
49
|
|
|
*/ |
50
|
1 |
|
public function getReferral(): Referral |
51
|
|
|
{ |
52
|
1 |
|
return $this->referral; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
1 |
|
public function getName(): string |
59
|
|
|
{ |
60
|
1 |
|
return self::NAME; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param array $payload |
65
|
|
|
* |
66
|
|
|
* @return \Kerox\Messenger\Event\ReferralEvent |
67
|
|
|
*/ |
68
|
1 |
|
public static function create(array $payload): self |
69
|
|
|
{ |
70
|
1 |
|
$senderId = $payload['sender']['id']; |
71
|
1 |
|
$recipientId = $payload['recipient']['id']; |
72
|
1 |
|
$timestamp = $payload['timestamp']; |
73
|
1 |
|
$referral = Referral::create($payload['referral']); |
74
|
|
|
|
75
|
1 |
|
return new static($senderId, $recipientId, $timestamp, $referral); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|