2017 © Pedro Pelรกez
 

library iguan-client-php

Client side of IguanREQ for PHP

image

iguan-req/iguan-client-php

Client side of IguanREQ for PHP

  • Wednesday, May 30, 2018
  • by viirtus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Iguan-client-php

Iguan docs here., (*1)

High-performance events library for PHP with Web and CLI Hooks with Iguan-server., (*2)

Installing

composer require iguan-req/iguan-client-php, (*3)

Basic usage

Create Iguan config file (_src/config.yml_):, (*4)

common:
  tag: 'First Event App'
  remote:
    client:
      socket:
        host: <IguanServerIp>
        port: 8081

Create event handler/emitter (_src/event.php_), (*5)

<?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('http://localhost/', '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
}

Run local PHP server:, (*6)

$ php -S localhost:8000

Navigate to http://localhost:8000/src/event.php. Now, you can check tmplocation and look inside generated files!, (*7)

Note: before usage, make sure that you have ran an Iguan-server., (*8)

More examples

A library was developed for almost zero-configuration, safety and handy running. You can see it in examples by yourself., (*9)

A library can be easily extended by using custom realization of almost each class. You can redefine default behavior of everything or even implement own algorithms, emitters, subscribers very easily., (*10)

Docs

Configuration, (*11)

Contribution

Feel free to PR!, (*12)

The Versions

30/05 2018

dev-master

9999999-dev

Client side of IguanREQ for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vishnevskiy Kirill

event webhook iguan

29/05 2018

0.9.0

0.9.0.0

Client side of IguanREQ for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vishnevskiy Kirill

event webhook iguan