PHP code example of wjy / rpc-helper

1. Go to this page and download the library: Download wjy/rpc-helper 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/ */

    

wjy / rpc-helper example snippets


#[RpcClient(registerCenter: 'nacos')]
class CalculatorServiceClient extends AbstractServiceClient implements CalculatorServiceInterface
{
    protected string $serviceName = 'CalculatorService';
    // ...
}

#[RpcClient(registerCenter: 'nacos', address: 'http://localhost:8848')]

#[RpcClient(nodes: ['localhost:9502'])]

#[RpcController(prefix: '/calculator')]  // prefix默认为类名首字母小写
class GoodsService implements GoodsServiceInterface
{
    #[RpcMapping(method: 'get')]  // path默认是方法名 接口: /calculator/add
    public function add($a, $b)
    {
        return $a + $b;
    }
    
    #[RpcMapping(path: 'minus', method: 'get')]  // 指定path地址 接口: /calculator/add
    public function minus($a, $b)
    {
        return $a + $b;
    }
}