Skip to content

Commit 1cb2609

Browse files
committed
Several bufixes in the action class. Readme examples improved (readability).
1 parent 13bda2b commit 1cb2609

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Action.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ public function parseRequest($request) {
9494
}
9595

9696
return \Yii::createObject([
97-
'class' => JsonRpcRequest::className(),
97+
'class' => JsonRpcRequest::class,
9898
'id' => $request->id,
9999
'route' => $route,
100-
'params' => $params
100+
'params' => $params,
101+
'originalRequest' => \Yii::$app->request,
101102
]);
102103
}
103104

@@ -215,14 +216,14 @@ public function runWithParams($params)
215216
$requests = $this->parseJsonRpcBody(file_get_contents('php://input'));
216217
}
217218
catch (\Exception $e) {
218-
$this->renderError($e, null);
219+
return $this->renderError($e, null);
219220
}
220221

221222
try {
222223
$requestObjects = $this->parseRequests($requests);
223224
}
224225
catch (\Exception $e) {
225-
$this->renderError($e, null);
226+
return $this->renderError($e, null);
226227
}
227228

228229
$response = [];

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ class ExampleController extends \yii\web\Controller {
6565
return "Params received: \$foo = $foo.";
6666
}
6767

68-
// Passing params as Yii request body params must be handy too, when we need to do a bulk
68+
// Passing params as Yii request body params must be handy too, when we need to do a massive
6969
// attribute assignment for example.
7070
public function actionTryWithBodyParams() {
71-
$output = "Params received: \n";
71+
$output = "Params received: ";
72+
$output_chunks = array();
7273
foreach (\Yii::$app->request->getBodyParams() as $name => $value) {
73-
$output .= "$name = $value\n";
74+
$output_chunks[] = "$name = $value\n";
7475
}
75-
return $output;
76+
return $output . implode(', ', $output_chunks) . '.';
7677
}
77-
78+
7879
}
7980
```
8081

@@ -87,10 +88,8 @@ Now this is how calls and responses will look like:
8788
<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar.", "id": 2}
8889
8990
// Using alternative entry point:
90-
-> {"jsonrpc": "2.0", "method": "api1.example.try-with-body-params", "params": {"foo": "bar"}, "id": 2}
91-
<- {"jsonrpc": "2.0", "result": "Params received:
92-
$foo = bar.
93-
", "id": 2}
91+
-> {"jsonrpc": "2.0", "method": "api1.example.try-with-body-params", "params": {"foo": "bar", "foo1": "bar1"}, "id": 2}
92+
<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar, $foo1 = bar1.", "id": 2}
9493
9594
-> {"jsonrpc": "2.0", "method": "api1.example.garbage", "id": 3}
9695
<- {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": 3}

0 commit comments

Comments
 (0)