diff --git a/config/rpc.php b/config/rpc.php new file mode 100644 index 0000000..c404ec9 --- /dev/null +++ b/config/rpc.php @@ -0,0 +1,47 @@ + env('APP_NAME'), + +// /** +// * log 存储路径 +// */ +// 'log_path' => storage_path('logs/rpc.log'),//rpc日志路径 + +// 'log_formatter' => \App\Logging\LogstashFormatter::class, //rpc日志格式 + + /** + * json rpc server 配置 + */ + 'server' => [ + 'name' => env('APP_NAME'), + 'map' => base_path('app/Rpc/method.php'), //rpc注册文件 + ], + /** + * json rpc client 配置 + */ + 'client' => [ + 'auth' => [ + 'local' => true, + 'base_uri' => env('RPC_AUTH_URI','http://auth.dev.haowumc.com'), + ], + 'erp' => [ + 'local' => true, + 'base_uri' => env('RPC_ERP_URI','http://erp.dev.haowumc.com'), + ], + 'crm' => [ + 'local' => true, + 'base_uri' => env('RPC_CRM_URI','http://crm.dev.haowumc.com'), + ], + 'api' => [ + 'local' => true, + 'base_uri' => env('RPC_API_URI','http://api.dev.haowumc.com'), + ], + 'op' => [ + 'local' => true, + 'base_uri' => env('RPC_OP_URI','http://op.dev.haowumc.com'), + ], + ], +]; diff --git a/src/Providers/BaseServiceProvider.php b/src/Providers/BaseServiceProvider.php new file mode 100644 index 0000000..f662a43 --- /dev/null +++ b/src/Providers/BaseServiceProvider.php @@ -0,0 +1,40 @@ +app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes([$source => config_path('rpc.php')], 'rpc'); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('rpc'); + } + + $this->mergeConfigFrom($source, 'rpc'); + } + + public function register() + { + $this->setupConfig(); + $this->app->singleton("rpc.logger", function () { + $config = config('rpc'); + $stream = new StreamHandler($this->app->storagePath() . $config['log_path']); + $stream->setFormatter(new $config['log_formatter']()); + $logger = new Logger('RPC.LOGGER'); + return $logger->pushHandler($stream); + }); + } + +} \ No newline at end of file diff --git a/src/Providers/ClientServiceProvider.php b/src/Providers/ClientServiceProvider.php index bd645d5..158746f 100644 --- a/src/Providers/ClientServiceProvider.php +++ b/src/Providers/ClientServiceProvider.php @@ -8,10 +8,8 @@ use JsonRpc\Exception\RpcServerException; use JsonRpc\Server\JsonRpcServer; -class ClientServiceProvider extends LoggerServiceProvider +class ClientServiceProvider extends BaseServiceProvider { - - /** * @throws RpcServerException */ diff --git a/src/Providers/LoggerServiceProvider.php b/src/Providers/LoggerServiceProvider.php deleted file mode 100644 index a420320..0000000 --- a/src/Providers/LoggerServiceProvider.php +++ /dev/null @@ -1,40 +0,0 @@ -app->configure('rpc'); - $config = config('rpc'); - if (!is_array($config)) { - throw new RpcServerException("Application's Rpc Config Undefind", 500); - } - $this->app->singleton("rpc.logger", function () use ($config) { - $default = [ - 'app' => '***', - 'log_path' => "/logs/rpc_monitor_" . date("Ymd") . ".log", - 'log_formatter' => \JsonRpc\Logging\LogstashFormatter::class, - ]; - $config = array_merge($default, $config); - $stream = new StreamHandler($this->app->storagePath() . $config['log_path']); - $stream->setFormatter(new $config['log_formatter']()); - $logger = new Logger('RPC.LOGGER'); - return $logger->pushHandler($stream); - }); - } - -} \ No newline at end of file diff --git a/src/Providers/LumenServerServiceProvider.php b/src/Providers/LumenServerServiceProvider.php index a24f898..5290194 100644 --- a/src/Providers/LumenServerServiceProvider.php +++ b/src/Providers/LumenServerServiceProvider.php @@ -10,7 +10,7 @@ use JsonRpc\Server\JsonRpcServer; use JsonRpc\Server\JsonRpcTool; use Laravel\Lumen\Application; -class LumenServerServiceProvider extends LoggerServiceProvider +class LumenServerServiceProvider extends BaseServiceProvider { /** @@ -31,8 +31,6 @@ class LumenServerServiceProvider extends LoggerServiceProvider 'prefix' => 'rpc', 'middleware' => 'rpc.security', ], function () { - - $this->app->configure('rpc'); $config = config('rpc.server'); $map = require_once $config['map']; $config['map'] = $map;