Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:registration] add missing property types #1500

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@
*/
final class MakeRegistrationForm extends AbstractMaker
{
private $userClass;
private $usernameField;
private $passwordField;
private $willVerifyEmail = false;
private $verifyEmailAnonymously = false;
private $idGetter;
private $emailGetter;
private $fromEmailAddress;
private $fromEmailName;
private string $userClass;
private string $usernameField;
private string $passwordField;
private bool $willVerifyEmail = false;
private bool $verifyEmailAnonymously = false;
private string $idGetter;
private string $emailGetter;
private string $fromEmailAddress;
private string $fromEmailName;
private ?Authenticator $autoLoginAuthenticator = null;
private $redirectRouteName;
private $addUniqueEntityConstraint;
private string $redirectRouteName;
private bool $addUniqueEntityConstraint = false;

public function __construct(
private FileManager $fileManager,
Expand All @@ -99,7 +99,7 @@ public static function getCommandDescription(): string
return 'Create a new registration form system';
}

public function configureCommand(Command $command, InputConfiguration $inputConf): void
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeRegistrationForm.txt'))
Expand Down Expand Up @@ -135,13 +135,12 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma

// see if it makes sense to add the UniqueEntity constraint
$userClassDetails = new ClassDetails($this->userClass);
$this->addUniqueEntityConstraint = false;

if (!$userClassDetails->hasAttribute(UniqueEntity::class)) {
$this->addUniqueEntityConstraint = $io->confirm(sprintf('Do you want to add a <comment>#[UniqueEntity]</comment> validation attribute to your <comment>%s</comment> class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass)));
$this->addUniqueEntityConstraint = (bool) $io->confirm(sprintf('Do you want to add a <comment>#[UniqueEntity]</comment> validation attribute to your <comment>%s</comment> class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass)));
}

$this->willVerifyEmail = $io->confirm('Do you want to send an email to verify the user\'s email address after registration?', true);
$this->willVerifyEmail = (bool) $io->confirm('Do you want to send an email to verify the user\'s email address after registration?');

if ($this->willVerifyEmail) {
$this->checkComponentsExist($io);
Expand All @@ -151,7 +150,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
$emailText[] = 'having to log in. To allow multi device email verification, we can embed a user id in the verification link.';
$io->text($emailText);
$io->newLine();
$this->verifyEmailAnonymously = $io->confirm('Would you like to include the user id in the verification link to allow anonymous email verification?', false);
$this->verifyEmailAnonymously = (bool) $io->confirm('Would you like to include the user id in the verification link to allow anonymous email verification?', false);

$this->idGetter = $interactiveSecurityHelper->guessIdGetter($io, $this->userClass);
$this->emailGetter = $interactiveSecurityHelper->guessEmailGetter($io, $this->userClass, 'email');
Expand Down Expand Up @@ -233,7 +232,18 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'Security\\'
);

$verifyEmailVars = ['will_verify_email' => $this->willVerifyEmail];

if ($this->willVerifyEmail) {
$verifyEmailVars = [
'will_verify_email' => $this->willVerifyEmail,
'email_verifier_class_details' => $verifyEmailServiceClassNameDetails,
'verify_email_anonymously' => $this->verifyEmailAnonymously,
'from_email' => $this->fromEmailAddress,
'from_email_name' => addslashes($this->fromEmailName),
'email_getter' => $this->emailGetter,
];

$useStatements = new UseStatementGenerator([
EntityManagerInterface::class,
TemplatedEmail::class,
Expand Down Expand Up @@ -333,17 +343,12 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'form_class_name' => $formClassDetails->getShortName(),
'user_class_name' => $userClassNameDetails->getShortName(),
'password_field' => $this->passwordField,
'will_verify_email' => $this->willVerifyEmail,
'email_verifier_class_details' => $verifyEmailServiceClassNameDetails,
'verify_email_anonymously' => $this->verifyEmailAnonymously,
'from_email' => $this->fromEmailAddress,
'from_email_name' => addslashes($this->fromEmailName),
'email_getter' => $this->emailGetter,
'redirect_route_name' => $this->redirectRouteName,
'redirect_route_name' => $this->redirectRouteName ?? null,
'translator_available' => $isTranslatorAvailable,
],
$userRepoVars,
$autoLoginVars,
$verifyEmailVars,
)
);

Expand Down
Loading