Created
November 25, 2014 04:08
-
-
Save Tim-Machine/02bfc88a02aa971403dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| error_reporting(E_ALL); | |
| ini_set('display_errors', '1'); | |
| require_once('./PHP_Json_RPC_2.0/vendor/autoload.php'); | |
| use Timmachine\PhpJsonRpc\Router; | |
| use Timmachine\PhpJsonRpc\Listener; | |
| class User | |
| { | |
| public function userCheck($hello, $test, $halp = "example optional parameter") | |
| { | |
| return ["hello"=>$hello, $test * 8, $halp]; | |
| } | |
| } | |
| $router = new Router(); | |
| $router->add('user.check', 'User@userCheck'); | |
| $customRequirements = [ | |
| [ | |
| 'key' => 'event', | |
| 'value' => null, | |
| 'errorMessage' => 'missing event', | |
| 'errorCode' => -34500 | |
| ] | |
| ]; | |
| $listener = new Listener($router, "2.0", $customRequirements); | |
| $listener->validateJson('{"jsonrpc": "2.0", "method": "user.check", "params":{"hello":45,"test":67}, "id": 1, "event": "test"}'); | |
| //$listener->validateJson('{"jsonrpc": "2.0", "method": "user_check", "params":[1,9], "id": 1}'); | |
| //$listener->validateJson('{"jsonrpc": "2.0", "method": "user_check", "params":{"data":{"test":45,"test2":67}, "derp":{"test":45,"test2":67}}, "id": 1}'); | |
| try { | |
| $listener->isValidJson(); | |
| $listener->processRequest(); | |
| $response = $listener->getResponse(); | |
| } catch (\Timmachine\PhpJsonRpc\RpcExceptions $e) { | |
| echo $e->getMessage(); | |
| $response = $listener->getResponse(); | |
| } | |
| print_r($response); // returns {"jsonrpc":"2.0","result":{"hello":45,"0":536,"1":"example optional parameter"},"id":1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment