监听 PHP 中的 Supervisor 事件

v0.2.0 2020-07-06 05:43 UTC

This package is auto-updated.

Last update: 2024-09-12 10:24:57 UTC


README

Latest Version Software License Total Downloads Test Suite

在 PHP 中监听 Supervisor 事件。

安装

通过 Composer

$ composer require supervisorphp/event

使用方法

Supervisor 有一个非常好的功能:通知(监听器)关于它的事件。

主要入口是 ListenerListeners 等待主监听逻辑中的 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)。请参阅 许可文件 了解更多信息。