2021-07-08 19:09:06 +08:00
|
|
|
<?php
|
2021-09-04 14:25:39 +08:00
|
|
|
declare(strict_types=1);
|
2021-07-08 19:09:06 +08:00
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
2022-01-22 20:08:19 +08:00
|
|
|
use App\Constant\RedisSubscribeChan;
|
2021-07-08 19:09:06 +08:00
|
|
|
|
2021-09-04 18:07:53 +08:00
|
|
|
class Message
|
2021-07-08 19:09:06 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $event
|
|
|
|
* @param array $data
|
|
|
|
* @param array $options
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-09-04 14:25:39 +08:00
|
|
|
public static function create(string $event, array $data, array $options = []): array
|
2021-07-08 19:09:06 +08:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'uuid' => uniqid((strval(mt_rand(0, 1000)))),
|
|
|
|
'event' => $event,
|
|
|
|
'data' => $data,
|
|
|
|
'options' => $options
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-09 22:57:19 +08:00
|
|
|
* 推送消息至 Redis 订阅通道中
|
|
|
|
*
|
2021-07-08 19:09:06 +08:00
|
|
|
* @param array $message
|
|
|
|
*/
|
|
|
|
public static function publish(array $message)
|
|
|
|
{
|
|
|
|
push_redis_subscribe(RedisSubscribeChan::WEBSOCKET_CHAN, $message);
|
|
|
|
}
|
|
|
|
}
|