pkg6/easy-rpc

实际RPC方法的详细方法

0.1.0 2024-08-30 06:10 UTC

This package is auto-updated.

Last update: 2024-09-02 01:19:18 UTC


README

composer require pkg6/easy-rpc

初始化

服务器

$s = new Server();
$s->addCallback('add', function ($a, $b) {
    return $a + $b;
});
$s->start();

客户端

$client = new Client();
$client->withURL("http://127.0.0.1:8000");
$add = $client->add(1,2);

添加对象类请参考:https://github.com/pkg6/easy-rpc/blob/main/tests/objects.php

接口

服务器接口

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();
}

客户端接口

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);
}