nicolasbeauvais /
laravel-transcribe
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NicolasBeauvais\Transcribe\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Illuminate\Support\Str; |
||
| 7 | use NicolasBeauvais\Transcribe\Manager; |
||
| 8 | |||
| 9 | class RemoveCommand extends Command |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * The name and signature of the console command. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $signature = 'transcribe:remove {key}'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The name and signature of the console command. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $description = 'Remove the given key from all language files.'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The Languages manager instance. |
||
| 27 | * |
||
| 28 | * @var \NicolasBeauvais\Transcribe\Manager |
||
| 29 | */ |
||
| 30 | private $manager; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Array of requested file in different languages. |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | protected $files; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * ListCommand constructor. |
||
| 41 | * |
||
| 42 | * @param \NicolasBeauvais\Transcribe\Manager $manager |
||
| 43 | * |
||
| 44 | * @return void |
||
| 45 | */ |
||
| 46 | public function __construct(Manager $manager) |
||
| 47 | { |
||
| 48 | parent::__construct(); |
||
| 49 | |||
| 50 | $this->manager = $manager; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Execute the console command. |
||
| 55 | * |
||
| 56 | * @return mixed |
||
| 57 | */ |
||
| 58 | public function handle() |
||
| 59 | { |
||
| 60 | try { |
||
| 61 | list($file, $key) = explode('.', $this->argument('key'), 2); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 62 | } catch (\ErrorException $e) { |
||
| 63 | $this->error('Could not recognize the key you want to remove.'); |
||
| 64 | |||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($this->confirm("Are you sure you want to remove \"{$file}.{$key}\"?")) { |
||
| 69 | if (Str::contains($file, '::')) { |
||
| 70 | try { |
||
| 71 | $parts = explode('::', $file); |
||
| 72 | |||
| 73 | $this->manager->setPathToVendorPackage($parts[0]); |
||
| 74 | |||
| 75 | $file = $parts[1]; |
||
| 76 | } catch (\ErrorException $e) { |
||
| 77 | $this->error('Could not recognize the package.'); |
||
| 78 | |||
| 79 | return; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->manager->removeKey($file, $key); |
||
| 84 | |||
| 85 | $this->info("{$file}.{$key} was removed successfully."); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 |