supervisorphp / event
监听 PHP 中的 Supervisor 事件
v0.2.0
2020-07-06 05:43 UTC
Requires
- php: >=7.3
Requires (Dev)
- guzzlehttp/streams: >=2.0
- overtrue/phplint: ^2.0
- phpspec/phpspec: ^6.2
- phpstan/phpstan: ^0.12.32
- phpstan/phpstan-strict-rules: ^0.12.2
Suggests
- guzzlehttp/streams: Used by Stream listener
README
在 PHP 中监听 Supervisor 事件。
安装
通过 Composer
$ composer require supervisorphp/event
使用方法
Supervisor 有一个非常好的功能:通知(监听器)关于它的事件。
主要入口是 Listener
。 Listeners
等待主监听逻辑中的 Handler
。当发生事件时,Handler
会收到一个 Notification
。
$handler = new \Supervisor\Event\Handler\CallbackHandler(function(\Supervisor\Event\Notification $notification) { echo $notification->getHeader('eventname'); }); $listener = new \Supervisor\Event\Listener\StandardListener; $listener->listen($handler);
目前可用的监听器
- 标准:监听标准输入流,写入标准输出
- Guzzle:使用
StreamInterface
提供一个简单的读取/写入接口
此外,您还可以使用两个异常来控制监听器本身
Supervisor\Exception\StopListenerException
:表示Listener
应该停止监听进一步的事件。Supervisor\Exception\EventHandlingFailedException
:表示处理事件失败,Listener
应该返回失败响应。
任何未处理的异常/错误都将导致监听器停止。
有关更多信息,请参阅 Supervisor 文档中的 事件。
测试
phpspec run
贡献
请参阅 CONTRIBUTING 了解详情。
鸣谢
许可
MIT 许可证(MIT)。请参阅 许可文件 了解更多信息。