add rpc server no config exception

This commit is contained in:
dongwei 2019-01-19 15:49:05 +08:00
parent 6838c279a2
commit 420725e262
2 changed files with 6 additions and 5 deletions

View File

@ -12,16 +12,14 @@ class ClientServiceProvider extends ServiceProvider
/** /**
* Register any application services. * @throws RpcServerException
*
* @return void
*/ */
public function register() public function register()
{ {
$this->app->configure('rpc'); $this->app->configure('rpc');
$config = config('rpc'); $config = config('rpc');
if (!is_array($config)) { if (!is_array($config)) {
throw new RpcServerException("Application's Rpc Config Undefind", 500); throw new RpcServerException("Application's Rpc Client Config Undefind", 500);
} }
$this->app->singleton('rpc', function () use ($config) { $this->app->singleton('rpc', function () use ($config) {
return new Client($config); return new Client($config);

View File

@ -4,6 +4,7 @@ namespace JsonRpc\Providers;
use App\Http\Middleware\JsonRpc; use App\Http\Middleware\JsonRpc;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use JsonRpc\Exception\RpcServerException;
use JsonRpc\Middleware\Security; use JsonRpc\Middleware\Security;
use JsonRpc\Server\JsonRpcDoc; use JsonRpc\Server\JsonRpcDoc;
use JsonRpc\Server\JsonRpcServer; use JsonRpc\Server\JsonRpcServer;
@ -33,7 +34,9 @@ class LumenServerServiceProvider extends ServiceProvider
$this->app->configure('rpc'); $this->app->configure('rpc');
$config = config('rpc.server'); $config = config('rpc.server');
if (!is_array($config)) {
throw new RpcServerException("Application's Rpc Server Config Undefind", 500);
}
$callback = function () use ($config) { $callback = function () use ($config) {
$server = new JsonRpcServer($config); $server = new JsonRpcServer($config);
return $server->handler(); return $server->handler();