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; + } +}