fresh/centrifugo-bundle

为 Symfony 应用程序提供与 WebSocket 服务器 Centrifugo 的通信。

资助包维护!
fre5h

安装次数: 129 272

依赖项: 0

建议者: 0

安全性: 0

星级: 78

关注者: 4

分支: 8

开放问题: 0

类型:symfony-bundle


README

📦 为 Symfony 应用程序提供与 Centrifugo WebSocket 服务器的通信。

Scrutinizer Quality Score Build Status CodeCov License Latest Stable Version Total Downloads StyleCI Gitter

特性 🎁

要求 🧐

  • PHP >= 8.3
  • Symfony 7.0

安装 🌱

$ composer req fresh/centrifugo-bundle
选择您需要的版本

默认情况下,Symfony Flex 将此包添加到 config/bundles.php 文件,并将所需的环境变量添加到 .env 文件。如果在包安装期间忽略了 contrib-recipe,则不会这样做。然后您必须手动执行此操作。

检查 config/bundles.php 文件

# config/bundles.php

return [
    // Other bundles...
    Fresh\CentrifugoBundle\FreshCentrifugoBundle::class => ['all' => true],
    // Other bundles...
];

检查 .env 文件并添加您的配置

# .env

###> fresh/centrifugo-bundle ###
CENTRIFUGO_API_KEY=secret-api-key
CENTRIFUGO_API_ENDPOINT=http://localhost:8000/api
CENTRIFUGO_SECRET=secret
###< fresh/centrifugo-bundle ###

CENTRIFUGO_API_KEY 应与 Centrifugo 配置文件中 api_key 选项的值相同。
CENTRIFUGO_SECRET 应与 Centrifugo 配置文件中 token_hmac_secret_key 选项的值相同。

ℹ️ 自定义包配置

使用 🧑‍🎓

Centrifugo 服务

<?php
declare(strict_types=1);

namespace App\Service;

use Fresh\CentrifugoBundle\Service\CentrifugoInterface;

class YourService
{
    public function __construct(private readonly CentrifugoInterface $centrifugo)
    {
    }

    public function example(): void
    {
        $this->centrifugo->publish(['foo' => 'bar'], 'channelName');
    }
}

ℹ️ 使用 Centrifugo 服务的更多示例

使用 JWT 令牌进行身份验证 🗝️

控制台命令 ⚒️

  • centrifugo:publish
  • centrifugo:broadcast
  • centrifugo:subscribe
  • centrifugo:unsubscribe
  • centrifugo:disconnect
  • centrifugo:refresh
  • centrifugo:presence
  • centrifugo:presence-stats
  • centrifugo:history
  • centrifugo:history-remove
  • centrifugo:channels
  • centrifugo:info

ℹ️ 使用控制台命令的更多示例

集成到 Symfony Web-Profiler 🎛️

在控制台命令中自动完成频道 🪄

贡献 🤝

阅读 CONTRIBUTING 文件。