moebius / events
Moebius 事件发射器实现
1.0.0
2022-06-24 14:17 UTC
Requires
- charm/testing: ^1.1
- moebius/loop: ^1.0
This package is not auto-updated.
Last update: 2024-09-14 22:32:06 UTC
README
Moebius 简单事件发射器实现。提供事件发射器接口和特性。
监听器 API
-
EventEmitterInterface::on( string $eventName, callable $handler )
订阅事件。 -
EventEmitterInterface::off( string $eventName = null, callable $handler = null )
从事件中取消订阅。 -
EventEmitterInterface::emit( EventInterface|string $eventName, mixed ...$arguments)
发射事件。您可以发射 EventInterface 对象,或者带有任意数量参数的命名事件。
静态事件发射器
在某些情况下,您可能想从尚未存在的对象订阅事件。这是通过静态事件发射器实现的。
StaticEventEmitterInterface::events(): EventEmitterInterface
此特定事件发射器将考虑您订阅的类在 PHP 类层次结构中的位置。因此,如果您订阅根类,您将接收到所有扩展类发射的事件。如果您订阅子类,您将不会接收到类层次结构中更高级别发射的事件。