config fix
This commit is contained in:
parent
9ae4d558c1
commit
4ac79e5c7e
47
config/rpc.php
Normal file
47
config/rpc.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
return [
|
||||
/**
|
||||
* app name
|
||||
*/
|
||||
'app' => 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'),
|
||||
],
|
||||
],
|
||||
];
|
40
src/Providers/BaseServiceProvider.php
Normal file
40
src/Providers/BaseServiceProvider.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace JsonRpc\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use JsonRpc\Exception\RpcServerException;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
class BaseServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
protected function setupConfig()
|
||||
{
|
||||
$source = realpath(__DIR__ . '/../../config/rpc.php');
|
||||
|
||||
if ($this->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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -8,10 +8,8 @@ use JsonRpc\Exception\RpcServerException;
|
|||
use JsonRpc\Server\JsonRpcServer;
|
||||
|
||||
|
||||
class ClientServiceProvider extends LoggerServiceProvider
|
||||
class ClientServiceProvider extends BaseServiceProvider
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @throws RpcServerException
|
||||
*/
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: dongwei
|
||||
* Date: 2019/1/18
|
||||
* Time: 1:36 PM
|
||||
*/
|
||||
|
||||
namespace JsonRpc\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use JsonRpc\Exception\RpcServerException;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
class LoggerServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
public function register()
|
||||
{
|
||||
$this->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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user