client load all config
This commit is contained in:
parent
d67bb4aefe
commit
2c96596e57
|
@ -31,6 +31,10 @@ class Client
|
||||||
*/
|
*/
|
||||||
protected $http;
|
protected $http;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* which server rpc call choose
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $server_config;
|
protected $server_config;
|
||||||
|
|
||||||
public function __construct($config)
|
public function __construct($config)
|
||||||
|
@ -56,7 +60,7 @@ class Client
|
||||||
*/
|
*/
|
||||||
public function endpoint($k)
|
public function endpoint($k)
|
||||||
{
|
{
|
||||||
$this->server_config = $this->config[$k];
|
$this->server_config = $this->config['client'][$k];
|
||||||
|
|
||||||
$default = [
|
$default = [
|
||||||
'app' => $k,
|
'app' => $k,
|
||||||
|
@ -106,7 +110,6 @@ class Client
|
||||||
try {
|
try {
|
||||||
$headers = [
|
$headers = [
|
||||||
'client_app' => $this->config['app'],
|
'client_app' => $this->config['app'],
|
||||||
'server_app' => $this->server_config['app']
|
|
||||||
];
|
];
|
||||||
$resp = $this->http->request('POST', 'rpc/json-rpc-v2.json', [
|
$resp = $this->http->request('POST', 'rpc/json-rpc-v2.json', [
|
||||||
'headers' => $headers,
|
'headers' => $headers,
|
||||||
|
|
|
@ -18,13 +18,13 @@ class ClientServiceProvider extends ServiceProvider
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->configure('rpc');
|
$this->app->configure('rpc');
|
||||||
$config = config('rpc.client');
|
$config = config('rpc');
|
||||||
|
|
||||||
$this->app->singleton('rpc', function () use ($config) {
|
$this->app->singleton('rpc', function () use ($config) {
|
||||||
return new Client($config);
|
return new Client($config);
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($config as $k => $item) {
|
foreach ($config['client'] as $k => $item) {
|
||||||
$this->app->singleton('rpc.' . $k, function () use ($k) {
|
$this->app->singleton('rpc.' . $k, function () use ($k) {
|
||||||
return app('rpc')->endpoint($k);
|
return app('rpc')->endpoint($k);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user