PublishCommand.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Dcat\Admin\Console;
  3. use Illuminate\Console\Command;
  4. class PublishCommand extends Command
  5. {
  6. /**
  7. * The console command name.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'admin:publish
  12. {--force : Overwrite any existing files}
  13. {--lang : Publish language files}
  14. {--assets : Publish assets files}
  15. {--migrations : Publish migrations files}
  16. {--config : Publish configuration files}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = "Re-publish dcat-admin's assets, configuration, language and migration files. If you want overwrite the existing files, you can add the `--force` option";
  23. /**
  24. * Execute the console command.
  25. *
  26. * @return void
  27. */
  28. public function handle()
  29. {
  30. $options = ['--provider' => 'Dcat\Admin\AdminServiceProvider'];
  31. if ($this->option('force')) {
  32. $options['--force'] = true;
  33. }
  34. $tags = $this->getTags();
  35. foreach ($tags as $tag) {
  36. $this->call('vendor:publish', $options + ['--tag' => $tag]);
  37. }
  38. if (! $tags) {
  39. $this->call('vendor:publish', $options);
  40. }
  41. $this->call('view:clear');
  42. }
  43. protected function getTags()
  44. {
  45. $tags = [];
  46. if ($this->option('lang')) {
  47. $tags[] = 'dcat-admin-lang';
  48. }
  49. if ($this->option('migrations')) {
  50. $tags[] = 'dcat-admin-migrations';
  51. }
  52. if ($this->option('assets')) {
  53. $tags[] = 'dcat-admin-assets';
  54. }
  55. if ($this->option('config')) {
  56. $tags[] = 'dcat-admin-config';
  57. }
  58. return $tags;
  59. }
  60. }