symfony/mercure

Symfony Mercure 组件

资助包维护!
dunglas
Tidelift

v0.6.5 2024-04-08 12:51 UTC

This package is auto-updated.

Last update: 2024-09-08 13:41:30 UTC


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!'));

资源