承接 timmachine/php-json-rpc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

timmachine/php-json-rpc

Composer 安装命令:

composer require timmachine/php-json-rpc

包简介

README 文档

README

Build Status

##Router the router allows you to map a string to a method inside of the class. The @ symbol is used to separate the class from the method name. It really doesn't do much on its own, but is a requirement for the Listener

$router = new \Timmachine\PhpJsonRpc\Router();
$router->add("math.subtract", 'BaseController@subtract');
$router->add("math.add", 'BaseController@add');

Listener

The listener is the brains of the operation. This bad boy will take your Json request twist it around and execute the method you want to call and then return the data to you in a properly formatted JsonRPC 2.0 format

    $json = '{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}';

    $listener = new \Timmachine\PhpJsonRpc\Listener($routes);

    try {

        //validate our json
        $listener->validateJson($json);

        // process the method request
        $listener->processRequest();

        // return our json response
        return $listener->getResponse();
    } catch (\Timmachine\PhpJsonRpc\RpcExceptions $e) {

        // even if there is an error you send a response back to your client that is properly formatted
        return $listener->getResponse();
    }

New JsonRPC versions?

lets make sure that we are forward thinking a little

    $listener = new \Timmachine\PhpJsonRpc\Listener($routes,'2.1');

Custom Requirements ?

Maybe your application has some custom requirements ?

$customRequirements = [
    [
        'key'          => 'myCustomKey',
        'value'        => null //no defined required value,
        'errorMessage' => 'my custom error message',
        'errorCode'    => -32600 // Invalid params
    ],
    [
        'key'          => 'myCustomKey2',
        'value'        => '1237485' //defined required value,
        'errorMessage' => 'myCustomKey2 is not set correctly or missing',
        'errorCode'    => -32600 // Invalid params
    ]
];

$mySpec = '3.0'

$listener = new \Timmachine\PhpJsonRpc\Listener($routes,$mySpec, $customRequirements);

Optional Params

class foo{
    public function bar($a = 2,$b = 3, $c = 4)
    {
     return $a + $b + $c;
    }
}

// example json to make the request
// '{"jsonrpc": "2.0", "method": "foo.bar", "params":[], "id": 1}';

//example response
//{"jsonrpc": "2.0", "result": 9, "id": 1}

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固