Skip to content

Commit

Permalink
Merge pull request #15 from DawidMazurek/clean-examples
Browse files Browse the repository at this point in the history
cleaned examples
  • Loading branch information
DawidMazurek authored Mar 19, 2018
2 parents 6062b6b + fc8d85f commit 886d7a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
8 changes: 3 additions & 5 deletions examples/server.php → examples/custromString.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
include __DIR__ . '/../vendor/autoload.php';
$requestBuilder = new JsonRpcRequestBuilder(new JsonSerializer());

$input = new InputStream($requestBuilder);

$input = new CustomStringInput(
'[{"jsonrpc":"2.0", "method": "sampleMethod", "params":[], "id":1}, {"jsonrpc":"2.0", "method": "sampleMethod", "params":[]}]',
$requestBuilder
Expand All @@ -27,10 +25,10 @@
$handler->registerForMethod('sampleMethod', $sampleHandler);

$server = new JsonRpcServer(
$handler,
new JsonRpcRequestBuilder(new JsonSerializer())
$handler
);

$response = $server->run($input);

echo json_encode($response->serialize());
header('ContentType: application/json');
echo $response->serialize();
30 changes: 30 additions & 0 deletions examples/postInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use DawidMazurek\JsonRpc\handler\MethodCallableHandler;
use DawidMazurek\JsonRpc\io\InputStream;
use DawidMazurek\JsonRpc\io\JsonSerializer;
use DawidMazurek\JsonRpc\request\JsonRpcRequestBuilder;
use DawidMazurek\JsonRpc\server\JsonRpcServer;

include __DIR__ . '/../vendor/autoload.php';
$requestBuilder = new JsonRpcRequestBuilder(new JsonSerializer());

$input = new InputStream($requestBuilder);

$sampleHandler = function(array $params) {
return "called with params:" . json_encode($params);
};

$handler = new MethodCallableHandler();
$handler->registerForMethod('sampleMethod', $sampleHandler);

$server = new JsonRpcServer(
$handler
);

$response = $server->run($input);

header('ContentType: application/json');
echo $response->serialize();

0 comments on commit 886d7a3

Please sign in to comment.