Total Complexity | 2 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class SimpleParser extends Parser |
||
6 | { |
||
7 | /** |
||
8 | * Strategy classes need to implement handle method. |
||
9 | */ |
||
10 | protected $strategies = []; |
||
11 | |||
12 | /** |
||
13 | * Encode output payload for websocket push. |
||
14 | * |
||
15 | * @param string $event |
||
16 | * @param mixed $data |
||
17 | * |
||
18 | * @return mixed |
||
19 | */ |
||
20 | public function encode(string $event, $data) |
||
21 | { |
||
22 | return json_encode( |
||
23 | [ |
||
24 | 'event' => $event, |
||
25 | 'data' => $data, |
||
26 | ] |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Input message on websocket connected. |
||
32 | * Define and return event name and payload data here. |
||
33 | * |
||
34 | * @param \Swoole\Websocket\Frame $frame |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | public function decode($frame) |
||
45 | ]; |
||
46 | } |
||
48 |