sunlong / thrift-laravel
use Thrift in Laravel
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
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.providers
in 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::class
toapp\Http\Kernel
in default, the request to
/rpc
will be process by Middleware, if you want to change this, please extendThriftServerMiddleware
and overwriteprocess
method
Client side
composer require sunlong/thrift-laravel
- add provider in
app.providers
:\sunlong\Thrift\ThriftServiceProvider::class
- setting
thrift.depends
in 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