diff --git a/src/CreateModuleCommand.php b/src/CreateModuleCommand.php index 8f9d5a2..16df06e 100644 --- a/src/CreateModuleCommand.php +++ b/src/CreateModuleCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; use Symfony\Component\Finder\Finder; @@ -36,6 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $fn = [$this->getHelper('question'), 'ask']; $ask = $this->partial($fn, $input, $output); + $namespace = $ask(new Question('Enter module namespace: ')); $assets = $ask(new ConfirmationQuestion('Add module assets example? [Y/n] ', true)); $settings = $ask(new ConfirmationQuestion('Add settings example? [Y/n] ', true)); @@ -55,7 +57,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int $fs->dumpFile("{$path}/{$file->getRelativePathname()}", $file->getContents()); } + // namespace + $this->replaceInFile( + "{$path}/bootstrap.php", + ['#// namespace#'], + $namespace ? ["namespace {$namespace};"] : [''], + ); + if ($assets) { + // add AssetsListener $find = ['#// includes#', '#// add event handlers ...#']; $replace = [ "\${0}\ninclude_once __DIR__ . 'src/AssetsListener';", @@ -65,9 +75,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]; $this->replaceInFile("{$path}/bootstrap.php", $find, $replace); + + // namespace + $this->replaceInFile( + "{$path}/src/AssetsListener.php", + ['#// namespace#'], + $namespace ? ["namespace {$namespace};"] : [''], + ); } if ($settings) { + // add SettingsListener $find = ['#// includes#', '#// add event handlers ...#']; $replace = [ "\${0}\ninclude_once __DIR__ . 'src/SettingsListener';", @@ -77,6 +95,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]; $this->replaceInFile("{$path}/bootstrap.php", $find, $replace); + + // namespace + $this->replaceInFile( + "{$path}/src/SettingsListener.php", + ['#// namespace#'], + $namespace ? ["namespace {$namespace};"] : [''], + ); } $output->writeln('Module created successfully.'); diff --git a/src/stubs/module/bootstrap.php b/src/stubs/module/bootstrap.php index 1934cab..781df57 100644 --- a/src/stubs/module/bootstrap.php +++ b/src/stubs/module/bootstrap.php @@ -1,5 +1,7 @@