1515use Symfony \Component \Console \Command \Command ;
1616use Symfony \Component \Console \Input \InputArgument ;
1717use Symfony \Component \Console \Input \InputInterface ;
18+ use Symfony \Component \Console \Input \InputOption ;
1819
1920abstract class AbstractBaseMakerCQRS extends AbstractMaker implements InputAwareMakerInterface
2021{
@@ -45,11 +46,12 @@ function getClassSuffix(): string
4546 }
4647
4748 /**
49+ * @param PathGenerator $pathGenerator
4850 * @return string
4951 */
50- function getNamespacePrefix (): string
52+ function getNamespacePrefix (PathGenerator $ pathGenerator ): string
5153 {
52- return 'Application \\' . $ this ->getClassSuffix () . '\\' ;
54+ return $ pathGenerator -> namespacePrefix ( 'Application \\' . $ this ->getClassSuffix () . '\\' ) ;
5355 }
5456
5557 /**
@@ -63,6 +65,13 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
6365 InputArgument::REQUIRED ,
6466 'The name of the ' . $ this ->getTarget () . ' class (e.g. <fg=yellow>Customer</>) ' ,
6567 )
68+ ->addOption (
69+ 'base-path ' ,
70+ null ,
71+ InputOption::VALUE_REQUIRED ,
72+ 'Base path from which to generate model & config. ' ,
73+ null
74+ )
6675 ;
6776 }
6877
@@ -78,21 +87,30 @@ public function configureDependencies(DependencyBuilder $dependencies, InputInte
7887 */
7988 public function interact (InputInterface $ input , ConsoleStyle $ io , Command $ command ): void
8089 {
90+ if (null === $ input ->getOption ('base-path ' )) {
91+ $ basePath = $ io ->ask (
92+ 'Which base path should be used? Default is " ' . PathGenerator::DEFAULT_BASE_PATH . '" ' ,
93+ PathGenerator::DEFAULT_BASE_PATH ,
94+ );
95+ $ input ->setOption ('base-path ' , $ basePath );
96+ }
8197 }
8298
8399 /**
84100 * @inheritDoc
85101 */
86102 public function generate (InputInterface $ input , ConsoleStyle $ io , Generator $ generator ): void
87103 {
104+ $ pathGenerator = new PathGenerator ($ input ->getOption ('base-path ' ));
105+
88106 $ entityClassNameDetails = $ generator ->createClassNameDetails (
89107 $ input ->getArgument ('name ' ),
90- $ this ->getNamespacePrefix (),
108+ $ this ->getNamespacePrefix ($ pathGenerator ),
91109 $ this ->getClassSuffix (),
92110 );
93111
94112 $ this ->generateEntity ($ entityClassNameDetails , $ generator );
95- $ this ->generateHandler ($ entityClassNameDetails , $ generator );
113+ $ this ->generateHandler ($ entityClassNameDetails , $ generator, $ pathGenerator );
96114
97115 $ this ->writeSuccessMessage ($ io );
98116 }
@@ -101,6 +119,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
101119 * @param ClassNameDetails $queryClassNameDetails
102120 * @param Generator $generator
103121 * @return void
122+ * @throws \Exception
104123 */
105124 private function generateEntity (ClassNameDetails $ queryClassNameDetails , Generator $ generator ): void
106125 {
@@ -122,12 +141,13 @@ private function generateEntity(ClassNameDetails $queryClassNameDetails, Generat
122141 * @param ClassNameDetails $queryClassNameDetails
123142 * @param Generator $generator
124143 * @return void
144+ * @throws \Exception
125145 */
126- private function generateHandler (ClassNameDetails $ queryClassNameDetails , Generator $ generator ): void
146+ private function generateHandler (ClassNameDetails $ queryClassNameDetails , Generator $ generator, PathGenerator $ pathGenerator ): void
127147 {
128148 $ classNameDetails = $ generator ->createClassNameDetails (
129149 $ queryClassNameDetails ->getShortName (),
130- $ this ->getNamespacePrefix (),
150+ $ this ->getNamespacePrefix ($ pathGenerator ),
131151 'Handler ' ,
132152 );
133153
0 commit comments