feast / pusher
FEAST框架的Pusher插件
v1.0.0-rc1
2021-04-20 04:26 UTC
Requires
- php: ^8.0.0
This package is auto-updated.
Last update: 2024-09-20 11:18:20 UTC
README
FEAST Pusher插件
安装
推荐使用composer安装。这允许快速设置。
使用Composer安装
运行composer install feast/pusher
。
在container.php
中,在文件底部添加以下内容。
$container->add(\FeastFramework\Pusher\Pusher::class,new \FeastFramework\Pusher\Pusher());
手动安装
或者,如果您不想使用composer,可以通过下载并将其放置在您选择的文件夹中手动安装此插件。您需要在将Pusher添加到容器之前在container.php
中添加路径映射。将以下代码块中的src
替换为您Pusher插件的安装路径。
/** @var \Feast\Autoloader $autoLoader */ $autoLoader->addPathMapping('FeastFramework\\Pusher', ['src']); $container->add(\FeastFramework\Pusher\Pusher::class,new \FeastFramework\Pusher\Pusher());
配置和用法
配置
通过在您的configs/config.php
中添加包含必要键的数组来配置Pusher插件。以下是一个示例。注意,如果您将配置命名空间命名为pusher
,则无需将其传递给各种方法。
$environment['production'] = [' pusher' => [ 'cluster' => 'us2', 'key' => 'Your-App-Key', 'secret' => 'Your-Secret-Key', 'appid' => 'App-ID' ] ];
注入和实例化
可以通过对参数\FeastFramework\Pusher\Pusher
进行类型提示来自动将Pusher插件注入到控制器和插件类中。要了解有关FEAST中依赖注入的更多信息,请参阅文档,在此处
或者,您可以直接通过调用new Pusher();
来实例化。
用法
Pusher对象具有以下方法。所有方法都接受各种参数以及可选的配置命名空间。方法返回表示来自Pusher API的数据的对象。有关详细信息,请参阅src/Response
文件夹。
getUsers
- 获取频道的用户信息- 参数
channel
pusherConfigNamespace
- 默认为pusher
- 参数
event
- 触发单个事件。- 参数
name
- 要触发的事件的名称。data
- 要传递给事件的数组或stdClass。channels
- 单个频道字符串,或要发布的频道数组。socketId
- 如果提供,则排除给定socket id的事件。默认为null。info
- 应返回的属性数组。当前有效值是user_count和subscription_count。pusherConfigNamespace
- 默认为pusher
- 参数
batchEvents
- 触发多个事件。- 参数
eventData
- 有关更多信息,请参阅Pusher文档。pusherConfigNamespace
- 默认为pusher
- 参数
channelInfo
- 获取单个频道的信息。- 参数
channel
- 要获取信息的频道名称infoType
- 要获取的属性数组。有效选项是user_count
和subscription_count
。pusherConfigNamespace
- 默认为pusher
- 参数
channelsInfo
- 获取多个频道的信息- 参数
prefix
- 通过指定的前缀过滤返回值。默认为null。infoType
- 要获取的属性数组。当前有效选项仅为user_count
。pusherConfigNamespace
- 默认为pusher
- 参数