PHP code example of switon / rpc
1. Go to this page and download the library: Download switon/rpc 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/ */
switon / rpc example snippets
use Switon\Core\Attribute\Autowired;
use Switon\Rpc\RpcInterface;
class UserService
{
#[Autowired] protected RpcInterface $rpc;
public function profile(int $userId): array
{
return $this->rpc->call(UserProfileService::class . '::profile', [$userId], 3);
}
}
class UserProfileService
{
public function profile(int $userId): array
{
return ['id' => $userId, 'name' => 'mark'];
}
}