1. Go to this page and download the library: Download katsana/minions 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/ */
namespace App\JsonRpc;
use Minions\Http\Request;
use Minions\Http\ValidatesRequests;
class MathAdd
{
use ValidatesRequests;
/**
* Handle the incoming request.
*
* @param \Minions\Http\Request $request
*
* @return mixed
*/
public function __invoke(Request $request)
{
return \array_sum($request->all());
}
/**
* Authorize the incoming request.
*
* @param \Minions\Http\Request $request
*
* @return bool
*/
public function authorize(Request $request): bool
{
return true;
}
}
use Minions\Router;
Router::rpc('math.add', 'App\JsonRpc\MathAdd');
/**
* Authorize the incoming request.
*
* @param \Minions\Http\Request $request
*
* @return bool
*/
public function authorize(Request $request): bool
{
return $request->id() === 'platform'; // only allow access from `platform`
}
namespace App\JsonRpc;
use App\User;
use Minions\Http\Request;
use Minions\Http\ValidatesRequests;
class User
{
use ValidatesRequests;
/**
* Handle the incoming request.
*
* @param \Minions\Http\Request $request
*
* @return mixed
*/
public function __invoke(Request $request)
{
$this->validate($request, [
'email' => ['
use Minions\Client\Message;
use Minions\Client\ResponseInterface;
use Minions\Minion;
Minion::broadcast('server-project-id', Minion::message(
'math.add', [1, 2, 3, 4]
))->then(function (ResponseInterface $response) {
assert(10, $response->getRpcResult());
});
Minion::run();