A test/demo component which has a few basic methods which demostrate how easy it is to define a class to interface to, a range of data types can be sent back from strings, arrays, objects, closures or even self/this for testing/example purposes.
Make sure you check out the components code, there is no complicated voodoo going on, its just a simple PHP class.
Require this package with composer using the following command:
$ composer require plinker/test
Creating a client instance is done as follows:
<?php
require 'vendor/autoload.php';
/**
* Initialize plinker client.
*
* @param string $server - URL to server listener.
* @param string $config - server secret, and/or a additional component data
*/
$client = new \Plinker\Core\Client(
'http://example.com/server.php',
[
'secret' => 'a secret password',
'array' => [
'key' => 'value'
]
]
);
// or using global function
$client = plinker_client('http://example.com/server.php', 'a secret password', [
'array' => [
'key' => 'value'
]
]);
Once setup, you call the class though its namespace to its method.
By calling this you can return the entire class to call locally.
Call
$client->test->this();
Response
Plinker\Test\Test Object
(
[config] => Array
(
[array] => Array
(
[key] => value
)
)
)
If your wondering where the config
array is coming from.. its passed in the connection, see above client section.
This shows a "getter" for the class which returns the config.
Call
$client->test->config();
Response
Array
(
[array] => Array
(
[key] => value
)
)
This shows returning a basic array. :/
Call
$client->test->an_array();
Response
Array
(
[0] => Hello World
)
This shows returning a closure (anonymous function) which was serialised with (opis/closure) SerializableClosure.
Call
$client->test->closure()('foo');
Response
foo
This shows running a closure (anonymous function) on the server from the client which was serialised with (opis/closure) SerializableClosure. This allows you to neatly mutate any data before its returned back from the server.
Call
$client->test->run_closure(function ($value = []) {
return implode(' ', $value);
})
Response
Hello World
This shows returning an object, in this example a DateTime object.
Call
$client->test->date();
Response
DateTime Object
(
[date] => 2018-05-11 15:53:34.655980
[timezone_type] => 3
[timezone] => UTC
)
This shows returning an string, in this example it returns the IP address of the server.
Call
$client->test->my_ip();
$client->test->your_ip();
Response
10.158.250.158
10.158.250.1
There are no tests setup for this component.
Please see CONTRIBUTING for details.
If you discover any security related issues, please contact me via https://cherone.co.uk instead of using the issue tracker.
If you use this project and make money from it or want to show your appreciation, please feel free to make a donation https://www.paypal.me/lcherone, thanks.
Get your company or name listed throughout the documentation and on each github repository, contact me at https://cherone.co.uk for further details.
The MIT License (MIT). Please see License File for more information.
See the organisations page for additional components.