增加 edge.php 生成
This commit is contained in:
parent
79f5833d16
commit
5b70a22901
70
app/Console/Commands/Cluster/PublishEdge.php
Normal file
70
app/Console/Commands/Cluster/PublishEdge.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Cluster;
|
||||
|
||||
use DragonCode\Support\Facades\Helpers\Str;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class PublishEdge extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'edge:publish {--node-id=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '生成 edge.php 到 bin 目录下。';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
// node_id 默认为随机字符串
|
||||
$node_id = $this->option('node-id') ?? Str::random(8);
|
||||
|
||||
// 读取 stubs/edge.stub
|
||||
$stub = file_get_contents(base_path('stubs/edge.stub'));
|
||||
|
||||
// 替换 stubs/edge.stub 中的内容
|
||||
$redis_host = config('database.redis.default.host');
|
||||
$redis_port = config('database.redis.default.port');
|
||||
$redis_password = config('database.redis.default.password');
|
||||
$redis_prefix = config('database.redis.options.prefix');
|
||||
|
||||
$stub = str_replace(
|
||||
[
|
||||
'{{REDIS_HOST}}',
|
||||
'{{REDIS_PORT}}',
|
||||
'{{REDIS_PASSWORD}}',
|
||||
'{{REDIS_PREFIX}}',
|
||||
'{{NODE_ID}}',
|
||||
],
|
||||
[
|
||||
$redis_host,
|
||||
$redis_port,
|
||||
$redis_password,
|
||||
$redis_prefix,
|
||||
$node_id,
|
||||
],
|
||||
$stub
|
||||
);
|
||||
|
||||
// 写入 bin/edge.php
|
||||
file_put_contents(base_path('bin/edge.php'), $stub);
|
||||
|
||||
$this->info('生成 edge.php 成功。请稍后编辑 bin/edge.php 文件。');
|
||||
$this->warn('此文件至关重要,请勿泄漏。');
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user