承接 hydrakit/event 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

hydrakit/event

Composer 安装命令:

composer require hydrakit/event

包简介

PSR-14 event dispatcher for Hydra PHP framework

README 文档

README

A minimal PSR-14 event dispatcher for the Hydra framework. It lets one subsystem announce that something happened without knowing — or depending on — whoever cares.

Like the rest of Hydra it binds to the PSR interfaces rather than inventing its own: events are plain objects, listeners are callables, and the dispatcher is a Psr\EventDispatcher\EventDispatcherInterface. There is nothing to learn beyond the standard.

What it ships

  • Dispatcher — a PSR-14 EventDispatcherInterface. dispatch($event) calls every matched listener in order and returns the same event object (so a caller can read what listeners left on a mutable event). Honours StoppableEventInterface.
  • ListenerProvider — a PSR-14 ListenerProviderInterface with one small, non-standard extension: listen(string $eventType, callable $listener). PSR-14 is silent on registration; this is how listeners get in. Matching is by instanceof, so a listener on a base class or marker interface fires for every subtype.
  • EventServiceProvider — binds a single shared ListenerProvider behind three keys (ListenerProvider, ListenerProviderInterface, EventDispatcherInterface) so the app registers into the same instance the dispatcher reads from.

It ships the mechanism only. Which events matter and who reacts to them is app policy — registered at the composition root, the same "ship the verb, the app supplies the noun" seam as auth's user provider.

Using it

Register the provider (before any provider whose services dispatch events):

$app->register(new SessionServiceProvider)
    ->register(new EventServiceProvider)
    ->register(new AuthServiceProvider)   // auth picks up the dispatcher if bound
    ->register(new AppServiceProvider);

Define an event — a plain object, immutable when it is just a fact:

final class OrderPlaced
{
    public function __construct(public readonly int $orderId) {}
}

Register a listener where the app composes itself (typically a provider's boot()):

$container->get(ListenerProvider::class)
    ->listen(OrderPlaced::class, [$auditListener, 'onOrderPlaced']);

Dispatch it from wherever the thing happens:

$this->events->dispatch(new OrderPlaced($order->id));

A subsystem that wants to stay usable without the event package should depend on a nullable ?EventDispatcherInterface and dispatch with ?-> — exactly what hydrakit/auth does.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固