net_bazzline/php_component_event

此包已 弃用 且不再维护。未建议替代包。

此自由项目旨在提供通用、简洁且不可变的 PHP 事件组件。

0.0.3 2017-01-28 16:32 UTC

This package is auto-updated.

Last update: 2021-03-05 12:29:45 UTC


README

我仍然喜欢这个想法,但目前没有继续开发它的用例。

PHP 事件组件

此自由项目旨在提供通用、简洁且不可变的 PHP 事件组件。

当前主分支的构建状态由 Travis CI 跟踪:最新稳定版

Scrutinizer 状态如下:代码质量

最低 PHP 版本是:最低 PHP 版本

查看 openhub.net

安装

手动安装

mkdir -p vendor/net_bazzline/php_component_event
cd vendor/net_bazzline/php_component_event
git clone https://github.com/bazzline/php_component_event .

使用 Packagist

composer require net_bazzline/php_component_event:dev-master

优点

  • 无依赖
  • 不可变对象
    • 默认不支持事件传播
    • 不支持更改主题
  • 事件包含
    • 发生时间
    • 名称
    • 来源
    • 主题 - 事件参数或数据(数组|集合)

术语

名称 描述
发生时间 事件何时发生
名称 此事件的唯一标识符(我尽可能使用可读性好的名称,而不是数字,并鼓励您也这样做)
来源 跟踪事件创建源的唯一标识符
主题 事件参数或数据,一个数组或类似集合的对象

想法

  • 无论您何时处理事件,由于事件执行太多或承担太多责任,因此会迅速变得复杂
  • 您可以使用 $event->name()$event instanceof MyEvent 仅监听特定事件
  • 而不是添加停止传播的选项,我鼓励您采取不同的方法
    • 创建一个通用的事件,在特殊情况下才触发实际事件(将传播逻辑移入事件)
    • 创建并触发一个拒绝先前更改的事件
  • 由于未实现停止传播的支持,因此在调度时不需要优先级(更少复杂性 :-))

提示

  • GenericEvent 继承,以添加对 public method source() 的 phpdoc 块的类型提示。
  • 使用或扩展 GenericEventBuilder 来设置您定义良好的事件名称、源等。

引用

Using an event is one of the best indicator that your information has to leave the current domain boundraies.
Keep the event simple, the structure of data should be the contract you as emitter and the event listener have agreed on.

来源 - @待办

I treat an event like a taken statement.
Once articulated, you can not change it since it is emitited and transported by your preferred transmission medium to the receiver.

All you can do is to add explenations or improvments to your statement.
Worst but possible, if you figure out you where wrong, your only chance is to withdraw your statement.
But everything you emit (or say) is another statement (or event).

来源 - @待办

[...] I characterize the data on a Domain Event as immutable source data that captures what the event is about and mutable processing data that records what the system does in response to it. [...]

来源

API

API 可在 bazzline.net 找到。

历史

  • 即将发布
    • @待办
      • 在此处和那里更新了一些措辞
  • 0.0.3 - 发布于 2017-01-28
    • 更新最低要求至 php 5.6
  • 0.0.2 - 发布于 29.08.2016
    • 添加了 GenericEventBuilder
    • 在类 GenericEvent 中添加了类型提示 DateTime
  • 0.0.1 - 发布于 21.08.2016

链接

结语

如果你喜欢它,请给它加星标 :-). 如果你需要它,请提出问题。如果你喜欢它,请拉取补丁。如果你使用了它,请写一篇博客。如果你非常喜欢它,请进行捐赠 :-]。