sunlong / thrift-laravel
在 Laravel 中使用 Thrift
0.3.4
2018-11-28 11:23 UTC
Requires
- php: >=5.6.0
- illuminate/http: 5.1.*|5.2.*
- illuminate/support: 5.1.*|5.2.*
- sunlong/thrift: ^0.9.3.5
- symfony/http-foundation: 2.7.*|2.8.*|3.0.*
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
README
在 Laravel 中使用 Thrift
如何使用
服务器端
-
composer require sunlong/thrift-laravel
-
在
app.providers
中添加提供者\sunlong\Thrift\ThriftServiceProvider::class
-
在文件
config/thrift.php
中设置thrift.providers
// first is service name, defined in thrift file // second in Service implement reference, e.g. // class ImageServcie implement \sunlong\ImageServiceIf ['sunlong.ImageService', \sunlong\ImageService::class],
-
将 Middleware
\sunlong\Thrift\Middleware\ThriftServerMiddleware::class
添加到app\Http\Kernel
默认情况下,对
/rpc
的请求将由 Middleware 处理,如果您想更改此行为,请扩展ThriftServerMiddleware
并重写process
方法
客户端
composer require sunlong/thrift-laravel
- 在
app.providers
中添加提供者\sunlong\Thrift\ThriftServiceProvider::class
- 在文件
config/thrift.php
中设置thrift.depends
// key is url // value is array of service name "https:///rpc" => [ 'sunlong.ImageService', ]
- 使用方法
/** @var \sunlong\Thrift\Contracts\ThriftClient $thriftClient */ $thriftClient = app(\sunlong\Thrift\Contracts\ThriftClient::class); /** @var \sunlong\ImageServiceIf $imageService */ $imageService = $thriftClient->with('sunlong.ImageService'); $result = $imageService->foo();
待办事项
- 单元测试