AppCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Dcat\Admin\Console;
  3. use Dcat\Admin\Support\Helper;
  4. use Illuminate\Filesystem\Filesystem;
  5. class AppCommand extends InstallCommand
  6. {
  7. /**
  8. * The console command name.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'admin:app {name}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Create new application';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return void
  23. */
  24. public function handle()
  25. {
  26. $this->addConfig();
  27. $this->initAdminDirectory();
  28. $this->info('Done.');
  29. }
  30. protected function addConfig()
  31. {
  32. /* @var Filesystem $files */
  33. $files = $this->laravel['files'];
  34. $app = Helper::slug($namespace = $this->argument('name'));
  35. $files->put(
  36. $config = config_path($app.'.php'),
  37. str_replace(
  38. ['DummyNamespace', 'DummyApp'],
  39. [$namespace, $app],
  40. $files->get(__DIR__.'/stubs/config.stub')
  41. )
  42. );
  43. config(['admin' => include $config]);
  44. }
  45. /**
  46. * Set admin directory.
  47. *
  48. * @return void
  49. */
  50. protected function setDirectory()
  51. {
  52. $this->directory = app_path($this->argument('name'));
  53. }
  54. }