77use Symfony \Component \Console \Attribute \AsCommand ;
88use Symfony \Component \Console \Input \InputArgument ;
99
10- #[AsCommand(name: 'make:sikessem-field ' )]
10+ #[AsCommand(name: 'make:sikessem-base- field ' )]
1111class MakeFieldCommand extends MakeCommand
1212{
13- protected $ signature = 'make:sikessem-field {name} {component} {column} {label? } {--f|force} ' ;
13+ protected $ signature = 'make:sikessem-field {name=Field : The name of the abstract field } {--f|force} ' ;
1414
15- protected $ description = 'Create a new field ' ;
15+ protected $ description = 'Create the base field ' ;
1616
1717 protected $ type = 'field ' ;
1818
19- protected function getStub ()
20- {
21- return $ this ->resolveStubPath ('/stubs/field.stub ' );
22- }
23-
2419 /**
2520 * Get the console command arguments.
2621 *
@@ -30,57 +25,31 @@ protected function getStub()
3025 protected function getArguments ()
3126 {
3227 return [
33- ['name ' , InputArgument::REQUIRED , 'The name of the ' .strtolower ($ this ->type )],
34- ['component ' , InputArgument::REQUIRED , 'The form component of the ' .strtolower ($ this ->type )],
35- ['column ' , InputArgument::REQUIRED , 'The table column of the ' .strtolower ($ this ->type )],
36- ['label ' , InputArgument::OPTIONAL , 'The label of the ' .strtolower ($ this ->type )],
28+ ['name ' , InputArgument::OPTIONAL , 'The name of the ' .str ($ this ->type )->lower ()],
3729 ];
3830 }
3931
32+ protected function getStub ()
33+ {
34+ return $ this ->resolveStubPath ('/stubs/field.stub ' );
35+ }
36+
4037 /**
41- * Build the class with the given name .
38+ * Get the desired class name from the input .
4239 *
43- * @param string $name
4440 * @return string
45- *
46- * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
4741 */
4842 #[\Override]
49- protected function buildClass ($ name )
50- {
51- $ stub = parent ::buildClass ($ name );
52-
53- $ this
54- ->replaceArgument ($ stub , 'component ' )
55- ->replaceArgument ($ stub , 'column ' )
56- ->replaceArgument ($ stub , 'name ' )
57- ->replaceArgument ($ stub , 'label ' );
58-
59- return $ stub ;
60- }
61-
62- protected function replaceArgument (string &$ stub , string $ name , string $ default = 'null ' ): static
43+ protected function getNameInput ()
6344 {
64- $ subject = $ name === 'name '
65- ? str ($ this ->getNameInput ())->beforeLast (ucfirst ($ this ->type ))->snake ()
66- : str ($ this ->argument ($ name ))->trim ();
67-
68- if ($ subject ->isEmpty ()) {
69- $ subject = $ default ;
70- } elseif (in_array ($ name , ['name ' , 'label ' ])) {
71- $ subject = $ subject ->replace (['\\' , '\'' ], ['\\\\' , '\\\'' ])->wrap ('\'' );
72- }
73-
74- $ stub = str_replace (['Dummy ' .ucfirst ($ name ), '{{ ' .$ name .' }} ' , '{{ ' .$ name .'}} ' ], (string ) $ subject , $ stub );
45+ $ name = str (parent ::getNameInput ());
46+ $ type = str ($ this ->type )->studly ()->toString ();
7547
76- return $ this ;
48+ return $ name -> beforeLast ( $ type )-> studly ()-> toString () ;
7749 }
7850
79- /**
80- * @param string $rootNamespace
81- */
8251 #[\Override]
83- protected function getDefaultNamespace ($ rootNamespace ): string
52+ protected function getDefaultNamespace ($ rootNamespace )
8453 {
8554 return $ rootNamespace .'\\Fields ' ;
8655 }
0 commit comments