SystemConfig.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Common\ConfigService;
  4. use Illuminate\Console\GeneratorCommand;
  5. use Illuminate\Filesystem\Filesystem;
  6. class SystemConfig extends GeneratorCommand
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'aix:config';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'load the aix system configs';
  20. protected $configService;
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @param Filesystem $filesystem
  25. * @param ConfigService $configService
  26. */
  27. public function __construct(Filesystem $filesystem, ConfigService $configService)
  28. {
  29. parent::__construct($filesystem);
  30. $this->configService = $configService;
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $configs="";
  40. $types=$this->configService->getTypeParents();
  41. foreach ($types as $type) {
  42. $configs.=" /*$type->name--$type->tips*/\n";
  43. $configs.=" '$type->alias' => [\n";
  44. foreach ($type->subTypes as $secondType) {
  45. $configs.=" /*$secondType->name--$secondType->tips*/\n";
  46. $configs.=" '$secondType->alias' => [\n";
  47. foreach ($secondType->subTypes as $thirdType) {
  48. $configs.=" /*$thirdType->name--$thirdType->tips*/\n";
  49. $configs.=" '$thirdType->alias' => [\n";
  50. foreach ($thirdType->configs as $config) {
  51. $configs.=" /*$config->name--$config->tips*/\n";
  52. $value=(!is_null($config->value))?$config->value:$config->default_value;
  53. $value=str_replace("'", "\'", $value);
  54. $configs.=" '$config->alias' => '$value',\n";
  55. }
  56. $configs.=" ],\n";
  57. }
  58. $configs.=" ],\n";
  59. }
  60. $configs.=" ],\n";
  61. }
  62. $this->files->put(config_path('aix.php'), $this->buildConfigFile($configs));
  63. $this->info('aix system config load successfully.');
  64. }
  65. /**
  66. * Get the stub file for the generator.
  67. *
  68. * @return string
  69. */
  70. protected function getStub()
  71. {
  72. return __DIR__.'/../stubs/system.stub';
  73. }
  74. protected function buildConfigFile($configs)
  75. {
  76. $stub = $this->files->get($this->getStub());
  77. $stub = str_replace(
  78. ['DummyConfig'],
  79. [$configs],
  80. $stub
  81. );
  82. return $stub;
  83. }
  84. }