1515namespace InitPHP \Framework \Console \Commands ;
1616
1717use InitPHP \Framework \Console \Utils \MakeFile ;
18- use \InitPHP \Console \{Input , Output };
18+ use \InitPHP \Framework \Console \Command ;
19+ use Symfony \Component \Console \Input \InputArgument ;
20+ use Symfony \Component \Console \Input \InputInterface ;
21+ use Symfony \Component \Console \Input \InputOption ;
22+ use Symfony \Component \Console \Output \OutputInterface ;
1923
20- class MakeModelCommand extends \ InitPHP \ Framework \ Console \ Command
24+ class MakeModelCommand extends Command
2125{
2226
23- /** @var string Command */
24- public $ command = 'make:model ' ;
27+ protected static $ defaultName = 'make:model ' ;
2528
26- public function execute ( Input $ input , Output $ output )
29+ protected function configure (): void
2730 {
28- $ name = trim ((!$ input ->hasSegment (0 ) ? $ output ->ask ("Name ? " , false ) : $ input ->getSegment (0 )), "/ " );
31+ $ this ->setDescription ('Creates a model. ' )
32+ ->addArgument ('name ' , InputArgument::REQUIRED , 'Model class name ' )
33+ ->addOption ('entity ' , 'e ' , InputOption::VALUE_NONE , 'Create Entity Class. ' );
34+ }
2935
36+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
37+ {
38+ $ name = trim ($ input ->getArgument ('name ' ), "/ " );
3039 $ entity = null ;
31- if ($ input ->hasOption ( ' e ' )) {
40+ if ($ input ->getOption ( ' entity ' )) {
3241 $ entity = MakeEntityCommand::makeEntity ($ name );
3342 }
3443 empty ($ entity ) && $ entity = "\\InitPHP \\Framework \\Database \\Entity::class " ;
@@ -45,21 +54,9 @@ public function execute(Input $input, Output $output)
4554 $ path .= $ name . ".php " ;
4655 $ make = new MakeFile (SYS_DIR . "Console/Templates/Model.txt " );
4756
48- if ($ make ->to ($ path , ["name " => $ name , "namespace " => $ namespace , 'entity ' => $ entity , 'schema ' => camelCase2SnakeCase ($ name )])) {
49- $ output ->success ("Ok " );
50- } else {
51- $ output ->error ("Error " );
52- }
53- }
54-
55- public function definition (): string
56- {
57- return 'Creates a model. ' ;
58- }
59-
60- public function arguments (): array
61- {
62- return [];
57+ return $ make ->to ($ path , ["name " => $ name , "namespace " => $ namespace , 'entity ' => $ entity , 'schema ' => camelCase2SnakeCase ($ name )])
58+ ? Command::SUCCESS
59+ : Command::FAILURE ;
6360 }
6461
6562}
0 commit comments