feast/pusher

FEAST框架的Pusher插件

v1.0.0-rc1 2021-04-20 04:26 UTC

This package is auto-updated.

Last update: 2024-09-20 11:18:20 UTC


README

FEAST Framework

PHPUnit Psalm Static analysis codecov

PHP Version Packagist License Docs

FEAST Pusher插件

此包是Pusher的插件,用于与FEAST框架一起使用。

安装

用法

安装

推荐使用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文件夹。

  1. getUsers - 获取频道的用户信息
    1. 参数
      1. channel
      2. pusherConfigNamespace - 默认为pusher
  2. event - 触发单个事件。
    1. 参数
      1. name - 要触发的事件的名称。
      2. data - 要传递给事件的数组或stdClass。
      3. channels - 单个频道字符串,或要发布的频道数组。
      4. socketId - 如果提供,则排除给定socket id的事件。默认为null。
      5. info - 应返回的属性数组。当前有效值是user_count和subscription_count。
      6. pusherConfigNamespace - 默认为pusher
  3. batchEvents - 触发多个事件。
    1. 参数
      1. eventData - 有关更多信息,请参阅Pusher文档
      2. pusherConfigNamespace - 默认为pusher
  4. channelInfo - 获取单个频道的信息。
    1. 参数
      1. channel - 要获取信息的频道名称
      2. infoType - 要获取的属性数组。有效选项是user_countsubscription_count
      3. pusherConfigNamespace - 默认为pusher
  5. channelsInfo - 获取多个频道的信息
    1. 参数
      1. prefix - 通过指定的前缀过滤返回值。默认为null。
      2. infoType - 要获取的属性数组。当前有效选项仅为user_count
      3. pusherConfigNamespace - 默认为pusher