fresh / centrifugo-bundle
为 Symfony 应用程序提供与 WebSocket 服务器 Centrifugo 的通信。
6.0.0
2024-09-11 20:20 UTC
Requires
- php: >=8.3
- fresh/datetime: ^4.0
- symfony/config: ~7.0
- symfony/console: ~7.0
- symfony/dependency-injection: ~7.0
- symfony/framework-bundle: ~7.0
- symfony/http-client: ~7.0
- symfony/http-foundation: ~7.0
- symfony/http-kernel: ~7.0
- symfony/security-core: ~7.0
- symfony/validator: ~7.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-11 20:20:42 UTC
README
📦 为 Symfony 应用程序提供与 Centrifugo WebSocket 服务器的通信。
特性 🎁
- 兼容最新的 Centrifugo 5.4.5 🚀
- 基于 Centrifugo HTTP API 的包装 🔌
- 使用 JWT 令牌(HMAC 算法)进行匿名、认证用户和私有频道的身份验证 🗝️
- 批量请求 以 JSON 流格式 💪
- 控制台命令 ⚒️️
- 集成到 Symfony Web-Profiler 🎛️
要求 🧐
- 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'); } }
使用 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 文件。