Laravel接入Apollo

55次阅读

共计 920 个字符,预计需要花费 3 分钟才能阅读完成。

废话不说,直接上代码
namespace App\Console\Commands\Apollo;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Org\Multilinguals\Apollo\Client\ApolloClient;

class SyncCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = ‘ue:apollo:sync’;

/**
* The console command description.
*
* @var string
*/
protected $description = ‘ 阿波罗同步 ’;

protected $config = [];

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
while (true) {
$this->doSync();
sleep(10);
}

}

protected function doSync()
{

if (!$this->config) {
$this->config = config(‘apollo’);
}

$server = Arr::get($this->config, ‘server’);

$appid = Arr::get($this->config, ‘app_id’);

$namespaces = Arr::get($this->config, ‘namespace’);

$apollo = new ApolloClient($server, $appid, $namespaces);

$error = $apollo->start();

logger()->error(null, [‘error’ => $error, ‘class’ => __CLASS__]);

}
}

正文完
 0