1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Console\Commands;
- use App\Services\Common\ConfigService;
- use Illuminate\Console\GeneratorCommand;
- use Illuminate\Filesystem\Filesystem;
- class SystemConfig extends GeneratorCommand
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'aix:config';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'load the aix system configs';
- protected $configService;
- /**
- * Create a new command instance.
- *
- * @param Filesystem $filesystem
- * @param ConfigService $configService
- */
- public function __construct(Filesystem $filesystem, ConfigService $configService)
- {
- parent::__construct($filesystem);
- $this->configService = $configService;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $configs="";
- $types=$this->configService->getTypeParents();
- foreach ($types as $type) {
- $configs.=" /*$type->name--$type->tips*/\n";
- $configs.=" '$type->alias' => [\n";
- foreach ($type->subTypes as $secondType) {
- $configs.=" /*$secondType->name--$secondType->tips*/\n";
- $configs.=" '$secondType->alias' => [\n";
- foreach ($secondType->subTypes as $thirdType) {
- $configs.=" /*$thirdType->name--$thirdType->tips*/\n";
- $configs.=" '$thirdType->alias' => [\n";
- foreach ($thirdType->configs as $config) {
- $configs.=" /*$config->name--$config->tips*/\n";
- $value=(!is_null($config->value))?$config->value:$config->default_value;
- $value=str_replace("'", "\'", $value);
- $configs.=" '$config->alias' => '$value',\n";
- }
- $configs.=" ],\n";
- }
- $configs.=" ],\n";
- }
- $configs.=" ],\n";
- }
- $this->files->put(config_path('aix.php'), $this->buildConfigFile($configs));
- $this->info('aix system config load successfully.');
- }
- /**
- * Get the stub file for the generator.
- *
- * @return string
- */
- protected function getStub()
- {
- return __DIR__.'/../stubs/system.stub';
- }
- protected function buildConfigFile($configs)
- {
- $stub = $this->files->get($this->getStub());
- $stub = str_replace(
- ['DummyConfig'],
- [$configs],
- $stub
- );
- return $stub;
- }
- }
|