raneomik / nette-mercure
🚀 Nette Mercure Extension: nette wrapper around https://github.com/symfony/mercure
v0.7.1
2026-11-15 00:35 UTC
Requires
- php: >=8.3
- lcobucci/jwt: ^5.6
- nette/di: ^3.2
- nette/http: ^3.4
- nette/schema: ^1.4
- symfony/mercure: ^0.9
- web-token/jwt-library: ^4.2
Requires (Dev)
- contributte/translation: ^2.0
- infection/infection: ^0.35.8
- latte/latte: ^3.1
- nette/application: ^3.3
- nette/bootstrap: ^3.3
- nette/security: ^3.2
- nette/tester: ^2.6
- phpro/grumphp: ^2.23
- phpstan/extension-installer: ^1.4
- phpstan/phpdoc-parser: ^2.3
- phpstan/phpstan-nette: ^2.0
- raneomik/infection-tester-adapter: ^0.3.3
- rector/rector: ^2.7
- symplify/easy-coding-standard: ^13.3
- tomasvotruba/type-coverage: ^2.2.0|^2.3
- tracy/tracy: ^2.12
Suggests
- contributte/translation: Localized hubs: one rendering per locale, on topics suffixed with it
- latte/latte: To render templates in broadcasts and use the {mercure()} and {mercureJWTToken()} functions
- nette/application: To use the subscriber, authorization and discovery services
- tracy/tracy: To debug publications and live events in the Tracy panel
Provides
None
Conflicts
None
Replaces
None
README
Work In Progress
🚀 Nette Mercure Extension: wrapper for symfony/mercure to use Mercure in Nette.
Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast, reliable and battery-efficient way. It is especially useful to publish real-time updates of resources served through web APIs, to reactive web and mobile apps.
Requirements
- PHP 8.3 or newer
nette/di3.2,nette/http3.4 or newer- A Mercure hub: the one built in FrankenPHP, or a standalone one
- Optional:
| Package | For |
|---|---|
latte/latte |
templates in broadcasts, {mercure()} and {mercureJWTToken()} |
nette/application |
subscriber, authorization and discovery services |
tracy/tracy |
debug panel |
Getting started
composer require raneomik/nette-mercure
Register the extension and configure the hub:
extensions: mercure: Raneomik\NetteMercure\Bridge\DI\MercureExtension(%debugMode%) mercure: url: 'https://example.com/.well-known/mercure' jwt: key: %mercureJwtKey% # openssl rand -hex 32, the same key as the hub's
Publish:
use Raneomik\NetteMercure\BroadcasterInterface; final class SomeService { public function __construct( private BroadcasterInterface $broadcaster, ) { } public function someAction(): void { $this->broadcaster->broadcast( topics: 'test-topic', data: 'Hello Nette from Mercure!', ); } }
Subscribe:
<div class="mercure-container">Waiting for updates...</div> <script type="module"> const eventSource = new EventSource({mercure('test-topic')}); eventSource.onmessage = event => { document.querySelector('.mercure-container').textContent = event.data; }; </script>
Documentation
- How-to guides: signing key, several hubs, templates, private updates, subscribing (JWT, cookie, discovery), Turbo Streams, locales, hot reload
- Reference: configuration, PHP services, Latte functions
- Debugging: Tracy panel, debug bus
How it works
- The hub implementation is picked at runtime: the FrankenPHP built-in hub when
mercure_publish()exists (Symfony\Component\Mercure\FrankenPhpHub), HTTP tourlotherwise (Symfony\Component\Mercure\Hub). The same compiled container works in FrankenPHP workers and in CLI commands, as long asurlis reachable from the CLI. - A publication is rendered once (once per locale with a translator) and sent as is to every subscriber of the topic.
Development
composer install && composer ci
Resources
- Based on symfony/mercure / documentation
- Mercure
- FrankenPHP Real-time and Hot-Reload
- Nette, Latte, Tester, Tracy
- Infection & home-made Tester adapter
- Demo: nette-frankenphp, a multiplayer game with a live lobby, Turbo Streams and Web Push
Known issues
- The
anonymousoption of Mercure in the Caddy configuration seems to work only withSymfony\Component\Mercure\FrankenPhpHuband the FrankenPHP built-inmercure_publishfunction. HttpClient shows errors such as "405 Method Not Allowed" in this case.