https://github.com/pkg6/easy-rpc
Implementing RPC in the simplest way possible
https://github.com/pkg6/easy-rpc
Last synced: 27 days ago
JSON representation
Implementing RPC in the simplest way possible
- Host: GitHub
- URL: https://github.com/pkg6/easy-rpc
- Owner: pkg6
- License: mit
- Created: 2024-12-10T01:09:24.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-11T16:03:39.000Z (5 months ago)
- Last Synced: 2025-04-05T06:11:14.425Z (about 2 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/pkg6/easy-rpc
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
~~~
composer require pkg6/easy-rpc
~~~## initialization
### Server
~~~
$s = new Server();
$s->addCallback('add', function ($a, $b) {
return $a + $b;
});
$s->start();
~~~### Client
~~~
$client = new Client();
$client->withURL("http://127.0.0.1:8000");
$add = $client->add(1,2);
~~~> addObjectClass refer to:https://github.com/pkg6/easy-rpc/blob/main/tests/objects.php
## Interfaces
### Server Interface
~~~
interface Server
{
/**
* Callback binding:
* @param $method
* @param Closure $callback
* @return $this
*/
public function addCallback($method, Closure $callback);/**
* Class/Method binding:
* @param $objectOrClass
* @return $this
*/
public function addObjectClass($objectOrClass);/**
* List of users to allow
* @param array $authentications
* @return $this
*/
public function withAuthentications(array $authentications);/**
* IP client restrictions
* @param array $hosts
* @return $this
*/
public function allowHosts(array $hosts);/**
* @return mixed
*/
public function start();
}
~~~### Client Interface
~~~
interface Client
{
/**
* @param $url
* @return $this
*/
public function withURL($url);/**
* @param $timeout
* @return $this
*/
public function withTimeout($timeout);/**
* @return $this
*/
public function withDebug();/**
* @param $username
* @param $password
* @return $this
*/
public function withAuthentication($username, $password);/**
* @param CHandle $handle
* @return $this
*/
public function withHandle(CHandle $handle);
}
~~~