RemoveModuleControllerCommand.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Console\Commands\Base;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\File;
  5. /**
  6. * 移除模块下的类
  7. * @package Prettus\Repository\Generators\Commands
  8. * @author Anderson Andrade <contato@andersonandra.de>
  9. */
  10. class RemoveModuleControllerCommand extends Command
  11. {
  12. /**
  13. * The name of command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'remove:module-controller {name} {key}';
  18. /**
  19. * The description of command.
  20. *
  21. * @var string
  22. */
  23. protected $description = '移除模块';
  24. /**
  25. * The type of class being generated.
  26. *
  27. * @var string
  28. */
  29. protected $type = 'setting';
  30. /**
  31. * Execute the command.
  32. *
  33. * @return void
  34. * @see fire()
  35. */
  36. public function handle()
  37. {
  38. $name = $this->argument('name');
  39. $key = $this->argument('key');
  40. try {
  41. if ($name) {
  42. $dirs[] = "app/Contracts/Repositories/{$name}";
  43. $dirs[] = "app/Http/Controllers/Admin/{$name}";
  44. $dirs[] = "app/Http/Controllers/Api/{$name}";
  45. $dirs[] = "app/Jobs/{$name}";
  46. $dirs[] = "app/Repositories/Criteria/{$name}";
  47. $dirs[] = "app/Repositories/Eloquent/{$name}";
  48. $dirs[] = "app/Repositories/Enums/{$name}";
  49. $dirs[] = "app/Repositories/Models/{$name}";
  50. $dirs[] = "app/Repositories/Presenters/{$name}";
  51. $dirs[] = "app/Repositories/Transformers/{$name}";
  52. $dirs[] = "app/Repositories/Validators/{$name}";
  53. $dirs[] = "app/Services/{$name}";
  54. $dirs[] = "app/Exports/{$name}";
  55. $dirs[] = "app/Console/Commands/{$name}";
  56. $dirs[] = "app/Http/Resources/{$name}";
  57. foreach ($dirs as $dir) {
  58. $path = base_path($dir);
  59. if (!File::isDirectory($path)) continue;
  60. $files = scandir($path);
  61. $files = array_diff($files, array('.', '..'));
  62. foreach ($files as $file) {
  63. if (strpos($file, $key) === 0) {
  64. $this->line($dir . '/' . $file);
  65. exec('rm ' . $path . '/' . $file);
  66. }
  67. }
  68. }
  69. $this->line('删除成功');
  70. }
  71. } catch (\Exception $exception) {
  72. dd($exception);
  73. }
  74. $this->line('ok');
  75. }
  76. }