PHP code example of boomdraw / rpc-core

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__)
);

// bootstrap/app.php

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    Boomdraw\RpcCore\Handler::class
);

// config/app.php

return [
    ...
    'rpc' => 'my-custom-uri',
    ...
];

// config/app.php

return [
    ...
    'rpc' => false,
    ...
];

// config/app.php

return [
    ...
    'routes' => false,
    ...
];



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')
bash
cp vendor/boomdraw/rpc-core/config/rpc.php config/rpc.php