MercureService
Publishes updates to a Mercure hub and mints the self-signed JWTs the hub expects for both server-side publish and browser-side subscribe. The hub is not called via any HTTP client abstraction — publish() drives cURL directly, so no other Milpa package is required to use this class.
MercureService::__construct()
public function __construct(string $hubUrl, string $publicUrl, string $publisherKey, string $subscriberKey):Parameters
| Name | Type | Description |
|---|---|---|
| $hubUrl | string | Internal hub URL used for server-side POST /.well-known/mercure |
| $publicUrl | string | Public hub URL the browser connects to for EventSource/SSE |
| $publisherKey | string | HMAC secret used to sign publisher JWTs |
| $subscriberKey | string | HMAC secret used to sign subscriber JWTs |
MercureService::publish()
public function publish(string $topic, array $data): voidPublish data to a Mercure topic.
Parameters
| Name | Type | Description |
|---|---|---|
| $topic | string | Topic URI (e.g. "conversations/123/messages") |
| $data | array<string, mixed> | Payload to send as JSON |
MercureService::generateSubscriberJwt()
public function generateSubscriberJwt(array $topics): stringGenerate a subscriber JWT for the browser EventSource connection.
Parameters
| Name | Type | Description |
|---|---|---|
| $topics | string[] | Topics the subscriber can listen to |
MercureService::getPublicUrl()
public function getPublicUrl(): stringThe public hub URL browsers should open their EventSource connection against.