1 | <?php declare(strict_types=1); |
||
5 | final class Event implements \JsonSerializable |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | private $event; |
||
11 | |||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | private $channel; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $data; |
||
21 | |||
22 | /** |
||
23 | * @param string $event |
||
24 | * @param array $data |
||
25 | * @param string $channel |
||
26 | */ |
||
27 | 15 | public function __construct(string $event, array $data, string $channel = '') |
|
33 | |||
34 | 15 | public static function createFromMessage(array $message): self |
|
35 | { |
||
36 | 15 | return new self( |
|
37 | 15 | $message['event'], |
|
38 | 15 | \is_array($message['data']) ? $message['data'] : \json_decode($message['data'], true), |
|
39 | 15 | $message['channel'] ?? '' |
|
40 | ); |
||
41 | } |
||
42 | |||
43 | 7 | public function jsonSerialize() |
|
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | 15 | public function getEvent() |
|
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | 15 | public function getChannel() |
|
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | 15 | public function getData() |
|
71 | |||
72 | 11 | public static function isError(Event $event): bool |
|
76 | |||
77 | 8 | public static function subscriptionSucceeded(Event $event): bool |
|
81 | |||
82 | 11 | public static function connectionEstablished(Event $event): bool |
|
86 | |||
87 | 11 | public static function subscribeOn(string $channel): array |
|
91 | |||
92 | 14 | public static function unsubscribeOn(string $channel): array |
|
96 | |||
97 | 2 | public static function ping(): array |
|
101 | } |
||
102 |