thrift-laravel maintained by sunlong
thrift-laravel
use Thrift in Laravel
How to use
Server side
-
composer require sunlong/thrift-laravel -
add provider to
app.providers:\sunlong\Thrift\ThriftServiceProvider::class -
setting
thrift.providersin fileconfig/thrift.php:// 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], -
add Middleware
\sunlong\Thrift\Middleware\ThriftServerMiddleware::classtoapp\Http\Kernelin default, the request to
/rpcwill be process by Middleware, if you want to change this, please extendThriftServerMiddlewareand overwriteprocessmethod
Client side
composer require sunlong/thrift-laravel- add provider in
app.providers:\sunlong\Thrift\ThriftServiceProvider::class - setting
thrift.dependsin fileconfig/thrift.php:// key is url // value is array of service name "http://localhost/rpc" => [ 'sunlong.ImageService', ] - usage:
/** @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();
TODO
- Unittest