waaseyaa/mercure 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

waaseyaa/mercure

最新稳定版本:v0.1.0-alpha.202

Composer 安装命令:

composer require waaseyaa/mercure

包简介

Mercure hub publisher for real-time SSE push in Waaseyaa

README 文档

README

Layer 0 — Foundation

Mercure hub publisher for real-time SSE push in Waaseyaa.

MercurePublisher POSTs JSON updates to a configured Mercure hub, minting a short-lived HS256 JWT (one-hour expiry, publish: ['*'] claim) for each request. Publication is best-effort: when the hub URL or JWT secret is unconfigured, or the hub returns a non-2xx response, publish() returns false rather than throwing — so a failed broadcast never crashes the primary request, matching the framework convention for non-critical side effects. Pure side-effect utility — no entity storage, no global state.

Install

Ships as part of waaseyaa/framework; consumers get it via the core, cms, or full metapackage. To pull it on its own:

composer require waaseyaa/mercure

Requires PHP >= 8.5 and the cURL extension. MercureServiceProvider is auto-discovered (extra.waaseyaa.providers) and binds MercurePublisher as a container singleton, reading config['mercure']['hub_url'] and config['mercure']['jwt_secret'].

Key API

MercurePublisher (@api, final)

public function __construct(string $hubUrl, string $jwtSecret)

// Publish $data (JSON-encoded) to $topic. Returns true on a 2xx hub
// response; false if unconfigured, on cURL failure, or non-2xx.
public function publish(string $topic, array $data): bool

// True only when both hubUrl and jwtSecret are non-empty.
public function isConfigured(): bool

MercureServiceProvider (final, extends Waaseyaa\Foundation\ServiceProvider\ServiceProvider)

Registers MercurePublisher as a singleton from the mercure config block:

public function register(): void

Usage

Resolve MercurePublisher from the container (or construct it directly) and push an update:

use Waaseyaa\Mercure\MercurePublisher;

$publisher = new MercurePublisher(
    hubUrl: 'https://hub.example.com/.well-known/mercure',
    jwtSecret: 'your-hub-jwt-secret',
);

if ($publisher->isConfigured()) {
    $publisher->publish('/notes/42', ['status' => 'updated']);
}

Because publish() is best-effort, you can call it unconditionally and ignore the return value in fire-and-forget paths — an unconfigured publisher simply returns false without side effects. Guard with isConfigured() (or inspect the boolean result) when you need to know whether the broadcast was actually attempted.

统计信息

  • 总下载量: 1.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-03-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固