| @@ 11-89 (lines=79) @@ | ||
| 8 | use Milkmeowo\Framework\Repository\Generators\CriteriaGenerator; |
|
| 9 | use Milkmeowo\Framework\Repository\Generators\Exceptions\FileAlreadyExistsException; |
|
| 10 | ||
| 11 | class CriteriaCommand extends Command |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * The name of command. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'starter:criteria'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The description of command. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Create a new criteria.'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * The type of class being generated. |
|
| 29 | * |
|
| 30 | * @var string |
|
| 31 | */ |
|
| 32 | protected $type = 'Criteria'; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Execute the command. |
|
| 36 | * |
|
| 37 | * @return void |
|
| 38 | */ |
|
| 39 | public function fire() |
|
| 40 | { |
|
| 41 | try { |
|
| 42 | (new CriteriaGenerator([ |
|
| 43 | 'name' => $this->argument('name'), |
|
| 44 | 'force' => $this->option('force'), |
|
| 45 | ]))->run(); |
|
| 46 | ||
| 47 | $this->info('Criteria created successfully.'); |
|
| 48 | } catch (FileAlreadyExistsException $ex) { |
|
| 49 | $this->error($this->type.' already exists!'); |
|
| 50 | ||
| 51 | return false; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * The array of command arguments. |
|
| 57 | * |
|
| 58 | * @return array |
|
| 59 | */ |
|
| 60 | public function getArguments() |
|
| 61 | { |
|
| 62 | return [ |
|
| 63 | [ |
|
| 64 | 'name', |
|
| 65 | InputArgument::REQUIRED, |
|
| 66 | 'The name of class being generated.', |
|
| 67 | null, |
|
| 68 | ], |
|
| 69 | ]; |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * The array of command options. |
|
| 74 | * |
|
| 75 | * @return array |
|
| 76 | */ |
|
| 77 | public function getOptions() |
|
| 78 | { |
|
| 79 | return [ |
|
| 80 | [ |
|
| 81 | 'force', |
|
| 82 | 'f', |
|
| 83 | InputOption::VALUE_NONE, |
|
| 84 | 'Force the creation if file already exists.', |
|
| 85 | null, |
|
| 86 | ], |
|
| 87 | ]; |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| @@ 11-88 (lines=78) @@ | ||
| 8 | use Milkmeowo\Framework\Repository\Generators\TransformerGenerator; |
|
| 9 | use Milkmeowo\Framework\Repository\Generators\Exceptions\FileAlreadyExistsException; |
|
| 10 | ||
| 11 | class TransformerCommand extends Command |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * The name of command. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'starter:transformer'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The description of command. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Create a new transformer.'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * The type of class being generated. |
|
| 29 | * |
|
| 30 | * @var string |
|
| 31 | */ |
|
| 32 | protected $type = 'Transformer'; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Execute the command. |
|
| 36 | * |
|
| 37 | * @return void |
|
| 38 | */ |
|
| 39 | public function fire() |
|
| 40 | { |
|
| 41 | try { |
|
| 42 | (new TransformerGenerator([ |
|
| 43 | 'name' => $this->argument('name'), |
|
| 44 | 'force' => $this->option('force'), |
|
| 45 | ]))->run(); |
|
| 46 | $this->info('Transformer created successfully.'); |
|
| 47 | } catch (FileAlreadyExistsException $e) { |
|
| 48 | $this->error($this->type.' already exists!'); |
|
| 49 | ||
| 50 | return false; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * The array of command arguments. |
|
| 56 | * |
|
| 57 | * @return array |
|
| 58 | */ |
|
| 59 | public function getArguments() |
|
| 60 | { |
|
| 61 | return [ |
|
| 62 | [ |
|
| 63 | 'name', |
|
| 64 | InputArgument::REQUIRED, |
|
| 65 | 'The name of model for which the transformer is being generated.', |
|
| 66 | null, |
|
| 67 | ], |
|
| 68 | ]; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * The array of command options. |
|
| 73 | * |
|
| 74 | * @return array |
|
| 75 | */ |
|
| 76 | public function getOptions() |
|
| 77 | { |
|
| 78 | return [ |
|
| 79 | [ |
|
| 80 | 'force', |
|
| 81 | 'f', |
|
| 82 | InputOption::VALUE_NONE, |
|
| 83 | 'Force the creation if file already exists.', |
|
| 84 | null, |
|
| 85 | ], |
|
| 86 | ]; |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||