Salah3id /
address-domains
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Salah3id\Domains\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Salah3id\Domains\Repository\Generators\CriteriaGenerator; |
||
| 7 | use Salah3id\Domains\Repository\Generators\FileAlreadyExistsException; |
||
| 8 | use Symfony\Component\Console\Input\InputArgument; |
||
| 9 | use Symfony\Component\Console\Input\InputOption; |
||
| 10 | use Salah3id\Domains\Traits\DomainCommandTrait; |
||
| 11 | |||
| 12 | |||
| 13 | /** |
||
| 14 | * Class CriteriaCommand |
||
| 15 | * @package Salah3id\Domains\Commands |
||
| 16 | * @author Anderson Andrade <[email protected]> |
||
| 17 | */ |
||
| 18 | class CriteriaCommand extends Command |
||
| 19 | { |
||
| 20 | |||
| 21 | use DomainCommandTrait; |
||
| 22 | /** |
||
| 23 | * The name of command. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $name = 'domain:criteria'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The description of command. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $description = 'Create a new criteria.'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The type of class being generated. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $type = 'Criteria'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Execute the command. |
||
| 45 | * |
||
| 46 | * @see fire() |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | public function handle(){ |
||
| 50 | $this->laravel->call([$this, 'fire'], func_get_args()); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Execute the command. |
||
| 55 | * |
||
| 56 | * @return void |
||
| 57 | */ |
||
| 58 | public function fire() |
||
| 59 | { |
||
| 60 | $domain = $this->getDomainNameForRepo(); |
||
| 61 | $domainPath = $this->laravel['domains']->getDomainPath($domain); |
||
| 62 | |||
| 63 | try { |
||
| 64 | (new CriteriaGenerator([ |
||
| 65 | 'name' => $this->argument('name'), |
||
| 66 | 'force' => $this->option('force'), |
||
| 67 | ],$domain,$domainPath))->run(); |
||
| 68 | |||
| 69 | $this->info("Criteria created successfully."); |
||
| 70 | } catch (FileAlreadyExistsException $ex) { |
||
| 71 | $this->error($this->type . ' already exists!'); |
||
| 72 | return false; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The array of command arguments. |
||
| 78 | * |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | public function getArguments() |
||
| 82 | { |
||
| 83 | return [ |
||
| 84 | [ |
||
| 85 | 'name', |
||
| 86 | InputArgument::REQUIRED, |
||
| 87 | 'The name of class being generated.', |
||
| 88 | null |
||
| 89 | ], |
||
| 90 | ]; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * The array of command options. |
||
| 95 | * |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function getOptions() |
||
| 99 | { |
||
| 100 | return [ |
||
| 101 | [ |
||
| 102 | 'force', |
||
| 103 | 'f', |
||
| 104 | InputOption::VALUE_NONE, |
||
| 105 | 'Force the creation if file already exists.', |
||
| 106 | null |
||
| 107 | ], |
||
| 108 | ]; |
||
| 109 | } |
||
| 110 | } |
||
| 111 |