iguan-req / iguan-client-php
PHP版本的IguanREQ客户端
0.9.0
2018-05-29 11:12 UTC
Requires
- php: >=5.6
- mustangostang/spyc: 0.6.2
- phpseclib/phpseclib: ~2.0
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-09-19 17:41:30 UTC
README
Iguan文档在此。
一个高性能的事件库,用于PHP,具有Web和CLI钩子,与Iguan-server一起使用。
安装
composer require iguan-req/iguan-client-php
基本用法
创建Iguan配置文件(src/config.yml)
common: tag: 'First Event App' remote: client: socket: host: <IguanServerIp> port: 8081
创建事件处理程序/发射器(src/event.php)
<?php use Iguan\Common\Data\EncodeDecodeException; use Iguan\Event\Builder\Builder; use Iguan\Event\Builder\Config; use Iguan\Event\Common\CommunicateException; use Iguan\Event\Common\EventDescriptor; use Iguan\Event\Event; use Iguan\Event\Subscriber\Subject; use Iguan\Event\Subscriber\SubjectHttpNotifyWay; use Iguan\Event\Subscriber\UriPair; use Iguan\Event\Subscriber\Verificator\InvalidVerificationException; require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; //load config from file $config = Config::fromFile(__DIR__ . '/' . 'config.yml'); $builder = new Builder($config); //build emitter with config values $emitter = $builder->buildEmitter(); try { //build subscriber with config values. //because subscriber can revoke previous subscriptions, there is may be a server //communication issues $subscriber = $builder->buildSubscriber(); //create HTTP-subscription (WebHook) subject for some man creating event //assuming we have localhost web root in "src" folder $subject = new Subject('man.create', new SubjectHttpNotifyWay(new UriPair('https:///', 'event.php'))); //add some handler for this subject $subject->addHandler(function (EventDescriptor $descriptor) { //a $man now is source array with event data inside $man = $descriptor->raisedEvent->getPayload(); //just store each new person in separated files file_put_contents('/tmp/event_man_' . $man['id'], json_encode($man)); }); //after adding handlers we must subscribe subject for registering in //backend event server and for being ready for receiving incoming events //handlers will be notified right here $subscriber->subscribe($subject); //fire event when some person created with person data inside $emitter->dispatch(Event::create('man.create', ['name' => 'John', 'age' => 28, 'id' => 1199])); } catch (CommunicateException $e) { die('Some server communication error: ' . $e->getMessage()); } catch (EncodeDecodeException $e) { die('Some data decoding error: ' . $e->getMessage()); } catch (InvalidVerificationException $impossible) { //verifying disabled }
运行本地PHP服务器
$ php -S localhost:8000
导航到https://:8000/src/event.php。现在,您可以检查tmplocation并查看生成的文件!
注意:在开始使用之前,请确保您已经运行了Iguan-server。
更多示例
为了几乎零配置、安全和方便地运行,开发了该库。您可以在示例中自行查看。
可以通过使用几乎每个类的自定义实现轻松扩展该库。您可以重新定义默认行为,甚至非常容易实现自己的算法、发射器、订阅者。
文档
贡献
请随意提交PR!