SkynetClient

Skynet offers a special class called SkynetClient witch can be helpul when you want to integrate Skynet with other applications.
Simple example of client class usage is in Skynet's package. It's example file:

skynet_client.php

SkynetClient class can be called from any other application. Only one required term is to place all Skynet classes (from /src directory) in place where your autoloader can access to them.
By default, Skynet offers simple autoloader, but you can use your own autoload function and e.g. place Skynet's classes into your /vendor directory.

When all of Skynet's classes are available for autoloader then you can create client object by:

$client = new Skynet\SkynetClient();

It creates SkynetClient instance and allow you to sending requests and receiving responses from Skynet clusters.
With client object you have access to two public objects:

$client->request

$client->response

Usage of both of them is similar to usage in Event Listeners, so if you want create parameter foo in your request then you can use:

$client->request->set('foo', 'bar');

For response receive you can use response object, so if you want to get value of field foo received in response you can use:

$foo = $client->response->get('foo');

Connections in client are offered by method:

$client->connect($clusterAddress, $newChainValue = null);

where:

- $clusterAddress is adress to cluster, e.g. "http://localhost/skynet/skynet.php"
- $newChainValue is new Chain Value to set on cluster [not required]

When Skynet client connects to another cluster then public property:

$client->isConnected

is set to TRUE.

So, simple usage of client can looks like code below:

<?php
/* Skynet Client example */

spl_autoload_register(function($class)
{
require_once 'src/'.str_replace("\\", "/", $class).'.php';
});

/* Create client */
$client = new Skynet\SkynetClient();

/* Set request field */
$client->request->set('foo', 'bar');

/* Send request and get response */
$client->connect('http://localhost/skynet/skynet.php');


/* If connected then get response */
if($client->isConnected)
{
echo $client->response->get('@foo');
}

Code above creates client object, sets request field foo to value bar and after that sends request to cluster http://localhost/skynet/skynet.php.
Finally if connection if sucessful then client gets response field @foo whitch is returned field from request parameter foo.

By default, client creates its own database but not stores remote clusters addresses. If you want to enable clusters storage in client then you must set config option:

client_registry

to TRUE.

And that's it. With SkynetClient you can connects with Skynet clusters from any place in your applications.
Full API Documentation is included in Skynet packages available on GitHub.