PHP code example of lanffy / laravel-thrift-plugin

1. Go to this page and download the library: Download lanffy/laravel-thrift-plugin 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/ */

    

lanffy / laravel-thrift-plugin example snippets


    return [
       'providers' => [
           [
               'Lanffy.Thrift.Express.HelloService', //thrift中定义的服务名
               ExpressService::class, // 服务实现类
           ],
           [
               'Lanffy.Thrift.Express.CalculateService', //多个服务按数组分开
               CalculateService::class,
           ],
        ],
    ];
    

    return [
        'client' => [
            'http://thrift.server.com/rpc' => [ //服务地址 
                'Lanffy.Thrift.Express.HelloService', //服务1名称
                'Lanffy.Thrift.Express.CalculateService', //服务2名称
            ],
        ],
    ];
    

        /**
         * A basic test example.
         *
         * @return void
         */
        public function testBasicTest()
        {
            $this->assertTrue(true);
            /**
             * @var $a ThriftClient
             */
            $a = app(ThriftClient::class);
    
            /**
             * @var  $service \Lanffy\Thrift\Express\HelloServiceIf
             */
            $service = $a->with('Lanffy.Thrift.Express.HelloService');
    
            $result = $service->hello('test');
            $this->assertEquals($result, 'testtest');
    
            /**
             * @var  $calculateService \Lanffy\Thrift\Express\CalculateServiceIf
             */
            $calculateService = $a->with('Lanffy.Thrift.Express.CalculateService');
            $res = $calculateService->add(1,2);
            $this->assertEquals($res, 3);
        }