12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Console\Commands\Base;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\File;
- /**
- * 移除模块下的类
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class RemoveModuleControllerCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $signature = 'remove:module-controller {name} {key}';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = '移除模块';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'setting';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle()
- {
- $name = $this->argument('name');
- $key = $this->argument('key');
- try {
- if ($name) {
- $dirs[] = "app/Contracts/Repositories/{$name}";
- $dirs[] = "app/Http/Controllers/Admin/{$name}";
- $dirs[] = "app/Http/Controllers/Api/{$name}";
- $dirs[] = "app/Jobs/{$name}";
- $dirs[] = "app/Repositories/Criteria/{$name}";
- $dirs[] = "app/Repositories/Eloquent/{$name}";
- $dirs[] = "app/Repositories/Enums/{$name}";
- $dirs[] = "app/Repositories/Models/{$name}";
- $dirs[] = "app/Repositories/Presenters/{$name}";
- $dirs[] = "app/Repositories/Transformers/{$name}";
- $dirs[] = "app/Repositories/Validators/{$name}";
- $dirs[] = "app/Services/{$name}";
- $dirs[] = "app/Exports/{$name}";
- $dirs[] = "app/Console/Commands/{$name}";
- $dirs[] = "app/Http/Resources/{$name}";
- foreach ($dirs as $dir) {
- $path = base_path($dir);
- if (!File::isDirectory($path)) continue;
- $files = scandir($path);
- $files = array_diff($files, array('.', '..'));
- foreach ($files as $file) {
- if (strpos($file, $key) === 0) {
- $this->line($dir . '/' . $file);
- exec('rm ' . $path . '/' . $file);
- }
- }
- }
- $this->line('删除成功');
- }
- } catch (\Exception $exception) {
- dd($exception);
- }
- $this->line('ok');
- }
- }
|