PHP code example of iguan-req / iguan-client-php

1. Go to this page and download the library: Download iguan-req/iguan-client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iguan-req / iguan-client-php example snippets



​
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;
​
te 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
}