symfony / mercure
Symfony Mercure 组件
v0.6.5
2024-04-08 12:51 UTC
Requires
- php: >=7.1.3
- symfony/deprecation-contracts: ^2.0|^3.0|^4.0
- symfony/http-client: ^4.4|^5.0|^6.0|^7.0
- symfony/http-foundation: ^4.4|^5.0|^6.0|^7.0
- symfony/polyfill-php80: ^1.22
- symfony/web-link: ^4.4|^5.0|^6.0|^7.0
Requires (Dev)
- lcobucci/jwt: ^3.4|^4.0|^5.0
- symfony/event-dispatcher: ^4.4|^5.0|^6.0|^7.0
- symfony/http-kernel: ^4.4|^5.0|^6.0|^7.0
- symfony/phpunit-bridge: ^5.2|^6.0|^7.0
- symfony/stopwatch: ^4.4|^5.0|^6.0|^7.0
- twig/twig: ^2.0|^3.0|^4.0
Suggests
- symfony/stopwatch: Integration with the profiler performances
README
Mercure 是一种协议,允许以方便、快速、可靠且节能的方式将数据更新推送到网页浏览器和其他 HTTP 客户端。它特别适用于发布通过 Web API 服务的资源的实时更新,适用于反应式 Web 和移动应用程序。
Mercure 组件实现了 Mercure 协议的 "发布者" 部分。[链接](https://mercure.rocks)
入门指南
$ composer require symfony/mercure
// change these values accordingly to your hub installation define('HUB_URL', 'https://demo.mercure.rocks/.well-known/mercure'); define('JWT', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.LRLvirgONK13JgacQ_VbcjySbVhkSmHy3IznH3tA9PM'); use Symfony\Component\Mercure\Hub; use Symfony\Component\Mercure\Jwt\StaticTokenProvider; use Symfony\Component\Mercure\Update; $hub = new Hub(HUB_URL, new StaticTokenProvider(JWT)); // Serialize the update, and dispatch it to the hub, that will broadcast it to the clients $id = $hub->publish(new Update('https://example.com/books/1.jsonld', 'Hi from Symfony!'));