Download the PHP package hibira-io/symfony-bundle without Composer
On this page you can find all versions of the php package hibira-io/symfony-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hibira-io/symfony-bundle
More information about hibira-io/symfony-bundle
Files in hibira-io/symfony-bundle
Package symfony-bundle
Short Description Hibira realtime for Symfony: UX Turbo Streams and Messenger without running a Mercure hub, plus channel auth, webhooks and push
License MIT
Homepage https://hibira.io
Informations about the package symfony-bundle
hibira-io/symfony-bundle
Realtime Symfony apps on Hibira, without running a
Mercure hub. Symfony UX Turbo Streams, Doctrine #[Broadcast] entities and
Symfony Messenger send their updates to Hibira, and the browser receives
them over WebSockets.
| Desktop | Phone |
|---|---|
What the bundle gives you:
- UX Turbo transport.
#[Broadcast]entities,turbo_stream_listen()andturbo_stream_from()/<twig:Turbo:Stream:From>work as they do with Mercure, with the transport namedhibira. - Messenger. Every event is a
PublishEventmessage. Route it to an async transport and a worker sends it, so a slow network never slows the request that saved the entity. - Signed channels. Each Turbo topic is a private channel that a browser can only join with the signature the page rendered for it.
- Size limit handling. A stream over your plan's event size limit becomes a Turbo page refresh instead of an error.
- Channel auth, webhooks and push.
POST /hibira/authfor your own private and presence channels, a verified webhook route that dispatches Symfony events, and push user tokens for iOS, Android and the web. bin/console hibira:checkto check the credentials and connection.
Supports Symfony 6.4, 7.x and 8.x (PHP 8.1+), UX Turbo 2 and 3.
Install
Symfony Flex enables the bundle, adds the Stimulus controller to
assets/controllers.json and pusher-js to your import map (or
package.json with Webpack Encore).
Copy the app ID, key and secret from your app page on
hibira.io/portal into .env.local (the Free plan
needs no card). The secret is shown once, when you create the app or rotate
it.
Import the routes:
Then check the setup:
On your app page, add your site's origin (for example
https://shop.example.com) to Allowed origins, or browsers can't
connect.
Configuration
Everything is optional. These are the defaults:
host, port and scheme take env placeholders too, such as
'%env(int:HIBIRA_PORT)%'.
Turbo Streams
Mark an entity with #[Broadcast] and give it a stream template, exactly as
in the UX Turbo docs:
Listen in a page. A class name follows every entity of that class, an entity follows that one entity, and any other string is a topic of your own:
Without Mercure installed, hibira becomes UX Turbo's default transport.
With both, pass it by name: turbo_stream_listen(topic, 'hibira'), or set
turbo.default_transport: hibira. #[Broadcast(transports: ['hibira'])]
limits an entity to Hibira.
Send a stream from anywhere, for example a Messenger handler reporting progress:
Each topic becomes the private channel private-turbo-<sha256(topic)>, and
the page carries an HMAC of that name, so a browser can't subscribe to a
topic its page didn't render. Free plans take events up to 4 KB, Hobby and
Starter 10 KB. A stream over the limit is replaced by
<turbo-stream action="refresh">, which reloads the page in place (set
turbo.oversize: throw to get a PayloadTooLargeException instead).
Messenger
Hibira::publish() and every Turbo broadcast dispatch
Hibira\SymfonyBundle\Message\PublishEvent. With no routing it is handled
during the request. Route it to a transport to send events from a worker:
Hibira::trigger() always sends right away.
Your own channels
Private and presence channels are authorized by POST /hibira/auth, which
asks your listeners. Nobody gets in until a listener calls allow():
In the browser, add {{ hibira_meta_tags() }} to your layout's <head>
and use the shared client:
With AssetMapper, add the module to importmap.php once:
'@hibira-io/symfony-bundle/hibira.js' => ['path' => '@hibira-io/symfony-bundle/hibira.js'].
Webhooks
Point your app's webhook at https://your-site/hibira/webhook. The bundle
checks X-Pusher-Signature (and, during a secret rotation,
X-Hibira-Previous-Signature) and dispatches one WebhookReceivedEvent per
event:
Push notifications
GET /hibira/push/token?user_id=... returns a user token for the signed-in
user, for setUserId() in the web, Android and iOS SDKs.
Coming from Mercure
| Mercure | Hibira |
|---|---|
symfony/mercure-bundle and a hub to run |
hibira-io/symfony-bundle, hosted |
MERCURE_URL, MERCURE_PUBLIC_URL, MERCURE_JWT_SECRET |
HIBIRA_APP_ID, HIBIRA_APP_KEY, HIBIRA_APP_SECRET |
turbo_stream_listen(topic) |
unchanged (transport hibira) |
#[Broadcast] |
unchanged |
HubInterface::publish(new Update(...)) |
Hibira::turboStream() or Hibira::publish() |
Update routed through Messenger |
PublishEvent routed through Messenger |
| Private updates with JWT cookies | Signed private channels, ChannelAuthorizationEvent |
Example
example/ is a live board on FrankenPHP: Doctrine
#[Broadcast] → Messenger worker → Hibira → Turbo Streams. Put your
credentials in example/.env.local, then:
and open http://localhost:8000 in two windows.
Development
中文摘要
hibira-io/symfony-bundle 讓 Symfony 專案不用自己架 Mercure hub,就能用
Hibira 推送即時更新:
- UX Turbo:
#[Broadcast]實體、turbo_stream_listen()、turbo_stream_from()照原本寫法使用,傳輸名稱為hibira。每個 topic 都是帶簽章的私有頻道。超過方案單一事件大小上限(Free 4 KB)時,自動改送 Turbo 頁面重新整理。 - Messenger:所有事件都是
PublishEvent訊息,路由到 async transport 就會改由 worker 發送。 - 頻道授權、Webhook、推播:
POST /hibira/auth(以ChannelAuthorizationEvent決定)、驗證簽章的 webhook 路由(派發WebhookReceivedEvent)、推播 user token。 - 安裝:
composer require hibira-io/symfony-bundle,在.env.local填入HIBIRA_APP_ID/HIBIRA_APP_KEY/HIBIRA_APP_SECRET,匯入路由後執行php bin/console hibira:check。記得在應用頁面的 Allowed origins 加入網站網域。 - 支援 Symfony 6.4、7.x、8.x(PHP 8.1+),UX Turbo 2 與 3。
example/是跑在 FrankenPHP 上的即時留言板範例。
All versions of symfony-bundle with dependencies
pusher/pusher-php-server Version ^7.2
symfony/config Version ^6.4|^7.0|^8.0
symfony/console Version ^6.4|^7.0|^8.0
symfony/dependency-injection Version ^6.4|^7.0|^8.0
symfony/event-dispatcher Version ^6.4|^7.0|^8.0
symfony/framework-bundle Version ^6.4|^7.0|^8.0
symfony/http-foundation Version ^6.4|^7.0|^8.0
symfony/http-kernel Version ^6.4|^7.0|^8.0
symfony/routing Version ^6.4|^7.0|^8.0