lao-liu / laravel-hprose
Hprose client/server providers for Laravel 5.x or Lumen 5.x
Installs: 1 176
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=5.6.4
- hprose/hprose: ^2.0
- illuminate/support: >=5.0
Requires (Dev)
- laravel/laravel: >=5.0
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-12-21 21:31:22 UTC
README
Hprose https://github.com/hprose
HPROSE
is a High Performance Remote Object Service Engine.
It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful.
Installation
# composer
composer require lao-liu/laravel-hprose
For Laravel 5.x
Configuration
# edit app/config/app.php # include the provider 'providers' => [ [...] Laoliu\LaravelHprose\HproseServiceProvider::class, ]; # include the alias 'aliases' => [ [...] 'RpcClient' => Laoliu\LaravelHprose\HproseClientFacade::class, 'RpcServer' => Laoliu\LaravelHprose\HproseServerFacade::class, 'RpcService' => Laoliu\LaravelHprose\HproseServiceFacade::class, ]; # Laravel config php artisan vendor:publish --provider="Laoliu\LaravelHprose\HproseServiceProvider"
config file
# config/hprose.php
Usage for laravel
Hprose client
use RpcClient as Rpc; $result = Rpc::someServerMethod($params);
Hprose server
Route::any('/api', function() { $server = app('RpcServer'); // Hprose support XmlRPC and JsonRPC // if want support XmlRpc $server->addFilter(new Hprose\Filter\XMLRPC\ServiceFilter()); // if want support JsonRpc $server->addFilter(new Hprose\Filter\JSONRPC\ServiceFilter()); $server->addInstanceMethods(new \App\Services\SomeHprosePublishServices()); $server->start(); });
Middleware setting
# app/Http/Middleware/VerifyCsrfToken.php [...] protected $except = [ 'api' // OR 'api*' ];
Done.
For Lumen 5.x
Configuration
# edit bootstrap/app.php $app->register(Laoliu\LaravelHprose\HproseServiceProvider::class); [...] class_alias('Laoliu\LaravelHprose\HproseClientFacade', 'RpcClient'); class_alias('Laoliu\LaravelHprose\HproseServerFacade', 'RpcServer'); class_alias('Laoliu\LaravelHprose\HproseServiceFacade', 'RpcService'); return $app;
Usage for lumen
Hprose client
$rpc = app('RpcClient')->useService('http://hproseServiceUrl/', $async); $result = $rpc->remoteMethods($params);
Hprose server
Route::any('/api', function() { $server = app('RpcServer'); // Hprose support XmlRPC and JsonRPC // if want support XmlRpc $server->addFilter(new Hprose\Filter\XMLRPC\ServiceFilter()); // if want support JsonRpc $server->addFilter(new Hprose\Filter\JSONRPC\ServiceFilter()); $server->addInstanceMethods(new \App\Services\SomeHprosePublishServices()); $server->start(); });
API Reference
Please refer to https://github.com/hprose/hprose-php