From 5b70a229013eb98533a6b866f89e48bb5a38ddd5 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 8 Feb 2023 21:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20edge.php=20=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Cluster/PublishEdge.php | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/Console/Commands/Cluster/PublishEdge.php diff --git a/app/Console/Commands/Cluster/PublishEdge.php b/app/Console/Commands/Cluster/PublishEdge.php new file mode 100644 index 0000000..b77029e --- /dev/null +++ b/app/Console/Commands/Cluster/PublishEdge.php @@ -0,0 +1,70 @@ +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; + } +}