@@ -114,7 +114,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
114114 }
115115
116116 $ io ->success ('Done! ' );
117- $ io ->note ('Don \'t forget to update your database schema, if needed. ' );
117+ $ io ->note ('Don \'t forget to update your database schema, if needed ' );
118118 }
119119
120120 private function generateUser (ConsoleStyle $ io ): void
@@ -222,9 +222,9 @@ private function generateUser(ConsoleStyle $io): void
222222 }
223223 };
224224
225- if ( isset ( $ this ->classMapping [CredentialInterface::class])) {
226- $ this -> credential = $ this -> classMapping [CredentialInterface::class];
227- } elseif ( $ io ->confirm ('Generate a user credential? ' )) {
225+ $ this -> credential = $ this ->classMapping [CredentialInterface::class] ?? null ;
226+
227+ if (! $ this -> hasUsername () && $ io ->confirm ('Generate a user credential? ' )) {
228228 $ credentials = [];
229229 foreach (glob (Configuration::getPackageDir ().'/Entity/Credential/*.php ' ) as $ file ) {
230230 if ('Anonymous ' === $ credential = basename ($ file , '.php ' )) {
@@ -404,14 +404,14 @@ private function generateControllers(ConsoleStyle $io): void
404404 }
405405 }
406406
407- $ usernameField = $ this ->credential ::getUsernameField ();
407+ $ usernameField = ( $ hasUsername = $ this ->hasUsername ()) ? $ this -> credential ::getUsernameField () : null ;
408408 $ hasPassword = $ this ->hasPassword ();
409409 $ nsForm = trim ($ io ->ask ('Provide the form namespace ' , 'App \\Form \\User \\' ), '\\' );
410410 $ nsController = trim ($ io ->ask ('Provide the controller namespace ' , 'App \\Controller \\User \\' ), '\\' );
411411 $ templateDir = trim ($ io ->ask ('Provide the base template directory ' , 'user/ ' ), '/ ' );
412412 $ baseTemplate = ltrim ($ io ->ask ('Provide the base template file ' , 'base.html.twig ' ), '/ ' );
413413 $ baseTemplateBlock = $ io ->ask ('Provide the base template block name ' , 'body ' );
414- $ hasRegistration = $ io ->confirm ('Add a registration controller? ' );
414+ $ hasRegistration = $ hasUsername && $ io ->confirm ('Add a registration controller? ' );
415415 $ hasLogin = $ hasPassword && $ io ->confirm ('Add a login and profile controller? ' );
416416 $ hasForgotPassword = $ this ->passwordReset && $ io ->confirm ('Add a forgot and reset password controller? ' );
417417
@@ -589,6 +589,11 @@ private function getClassFileName(string $class): string
589589 return $ this ->projectDir .'/src/ ' .str_replace ('\\' , '/ ' , $ class ).'.php ' ;
590590 }
591591
592+ private function hasUsername (): bool
593+ {
594+ return $ this ->credential && Entity \Credential \Anonymous::class !== $ this ->credential ;
595+ }
596+
592597 private function hasPassword (): bool
593598 {
594599 return $ this ->credential && false !== strpos ($ this ->credential , 'Password ' );
0 commit comments