其余文件
This commit is contained in:
37
app/common/websocket/Parser.php
Normal file
37
app/common/websocket/Parser.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\websocket;
|
||||
|
||||
|
||||
class Parser
|
||||
{
|
||||
/**
|
||||
* @notes 数组数据转json
|
||||
* @param string $event
|
||||
* @param $data
|
||||
* @return false|string
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 18:27
|
||||
*/
|
||||
public function encode(string $event, $data)
|
||||
{
|
||||
return json_encode(['event' => $event, 'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes json转数组数据
|
||||
* @param $data
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 18:28
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
$result = json_decode($data, true);
|
||||
return [
|
||||
'event' => $result['event'] ?? null,
|
||||
'data' => $result['data'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user