Salah3id /
address-domains
| 1 | <?php |
||
| 2 | namespace Salah3id\Domains\Commands; |
||
| 3 | |||
| 4 | use Illuminate\Console\Command; |
||
| 5 | use Illuminate\Support\Collection; |
||
| 6 | use Symfony\Component\Console\Input\InputArgument; |
||
| 7 | use Symfony\Component\Console\Input\InputOption; |
||
| 8 | use Salah3id\Domains\Traits\DomainCommandTrait; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class EntityCommand |
||
| 12 | * @package Salah3id\Domains\Commands |
||
| 13 | * @author Anderson Andrade <[email protected]> |
||
| 14 | */ |
||
| 15 | class EntityCommand extends Command |
||
| 16 | { |
||
| 17 | |||
| 18 | use DomainCommandTrait; |
||
| 19 | /** |
||
| 20 | * The name of command. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $name = 'domain:entity'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The description of command. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $description = 'Create a new entity.'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var Collection |
||
| 35 | */ |
||
| 36 | protected $generators = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Execute the command. |
||
| 40 | * |
||
| 41 | * @see fire() |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | public function handle(){ |
||
| 45 | $this->laravel->call([$this, 'fire'], func_get_args()); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Execute the command. |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function fire() |
||
| 54 | { |
||
| 55 | $domain = $this->getDomainNameForRepo(); |
||
| 56 | $domainPath = $this->laravel['domains']->getDomainPath($domain); |
||
| 57 | |||
| 58 | if ($this->confirm('Would you like to create a Presenter? [y|N]')) { |
||
| 59 | $this->call('domain:presenter', [ |
||
| 60 | 'name' => $this->argument('name'), |
||
| 61 | '--force' => $this->option('force'), |
||
| 62 | 'domain' => $domain, |
||
| 63 | 'domain-path' => $domainPath |
||
| 64 | ]); |
||
| 65 | } |
||
| 66 | |||
| 67 | $validator = $this->option('validator'); |
||
| 68 | if (is_null($validator) && $this->confirm('Would you like to create a Validator? [y|N]')) { |
||
| 69 | $validator = 'yes'; |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($validator == 'yes') { |
||
| 73 | $this->call('domain:validator', [ |
||
| 74 | 'name' => $this->argument('name'), |
||
| 75 | '--rules' => $this->option('rules'), |
||
| 76 | '--force' => $this->option('force'), |
||
| 77 | 'domain' => $domain, |
||
| 78 | 'domain-path' => $domainPath |
||
| 79 | ]); |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($this->confirm('Would you like to create a Controller? [y|N]')) { |
||
| 83 | |||
| 84 | $resource_args = [ |
||
| 85 | 'name' => $this->argument('name'), |
||
| 86 | 'domain' => $domain, |
||
| 87 | 'domain-path' => $domainPath |
||
| 88 | ]; |
||
| 89 | |||
| 90 | // Generate a controller resource |
||
| 91 | $controller_command = ((float) app()->version() >= 5.5 ? 'make:rest-controller' : 'make:resource'); |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 92 | $this->call($controller_command, $resource_args); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->call('domain:repository', [ |
||
| 96 | 'name' => $this->argument('name'), |
||
| 97 | '--fillable' => $this->option('fillable'), |
||
| 98 | '--rules' => $this->option('rules'), |
||
| 99 | '--validator' => $validator, |
||
| 100 | '--force' => $this->option('force'), |
||
| 101 | 'domain' => $domain, |
||
| 102 | 'domain-path' => $domainPath |
||
| 103 | ]); |
||
| 104 | |||
| 105 | $this->call('domain:repo-bindings', [ |
||
| 106 | 'name' => $this->argument('name'), |
||
| 107 | '--force' => $this->option('force'), |
||
| 108 | 'domain' => $domain, |
||
| 109 | 'domain-path' => $domainPath |
||
| 110 | ]); |
||
| 111 | } |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * The array of command arguments. |
||
| 116 | * |
||
| 117 | * @return array |
||
| 118 | */ |
||
| 119 | public function getArguments() |
||
| 120 | { |
||
| 121 | return [ |
||
| 122 | [ |
||
| 123 | 'name', |
||
| 124 | InputArgument::REQUIRED, |
||
| 125 | 'The name of class being generated.', |
||
| 126 | null |
||
| 127 | ], |
||
| 128 | ]; |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | /** |
||
| 133 | * The array of command options. |
||
| 134 | * |
||
| 135 | * @return array |
||
| 136 | */ |
||
| 137 | public function getOptions() |
||
| 138 | { |
||
| 139 | return [ |
||
| 140 | [ |
||
| 141 | 'fillable', |
||
| 142 | null, |
||
| 143 | InputOption::VALUE_OPTIONAL, |
||
| 144 | 'The fillable attributes.', |
||
| 145 | null |
||
| 146 | ], |
||
| 147 | [ |
||
| 148 | 'rules', |
||
| 149 | null, |
||
| 150 | InputOption::VALUE_OPTIONAL, |
||
| 151 | 'The rules of validation attributes.', |
||
| 152 | null |
||
| 153 | ], |
||
| 154 | [ |
||
| 155 | 'validator', |
||
| 156 | null, |
||
| 157 | InputOption::VALUE_OPTIONAL, |
||
| 158 | 'Adds validator reference to the repository.', |
||
| 159 | null |
||
| 160 | ], |
||
| 161 | [ |
||
| 162 | 'force', |
||
| 163 | 'f', |
||
| 164 | InputOption::VALUE_NONE, |
||
| 165 | 'Force the creation if file already exists.', |
||
| 166 | null |
||
| 167 | ] |
||
| 168 | ]; |
||
| 169 | } |
||
| 170 | } |
||
| 171 |