1. Go to this page and download the library: Download boomdraw/rpc-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
boomdraw / rpc-core example snippets
// bootstrap/app.php
$app = new Boomdraw\RpcCore\Application(
dirname(__DIR__)
);
return [
/*
| Handlers default namespace and suffix.
*/
'handler' => [
'path' => 'App\Rpc\Handlers',
'suffix' => 'Handler',
],
/*
| List of custom handlers with its paths.
| Handler key must be in a studly caps case
| Example:
| 'CustomHelper' => App\Handlers\CustomRpcHandler::class
*/
'handlers' => [
//
],
];
// bootstrap/app.php
$app->configure('rpc');
// app/Rpc/Handlers/ExampleHandler.php
namespace App\Rpc\Handlers;
use Boomdraw\RpcCore\Handler;
use Illuminate\Http\Request;
class ExampleHandler extends Handler
{
public function __invoke(Request $request)
{
return ['data' => ['hello' => $request->hello]];
}
public function message(Request $request): string
{
return $request->message;
}
public function throwException(): void
{
abort(500, 'Yeah!');
}
}
// function context(string $key, $default = null)
context('userId', 'default')