Skip to content

Commit 9e552f0

Browse files
committed
lets use a factory method to generate the helper
1 parent 0375f92 commit 9e552f0

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/Generator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
1717
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1818
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
19+
use Symfony\Bundle\MakerBundle\Util\TemplateClassDetails;
1920

2021
/**
2122
* @author Javier Eguiluz <[email protected]>
@@ -156,6 +157,11 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st
156157
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix);
157158
}
158159

160+
public function createClassHelper(string $fullyQualifiedClassName): TemplateClassDetails
161+
{
162+
return new TemplateClassDetails($fullyQualifiedClassName, $this->phpCompatUtil->canUseTypedProperties());
163+
}
164+
159165
public function getRootDirectory(): string
160166
{
161167
return $this->fileManager->getRootDirectory();

src/Maker/MakeRegistrationForm.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ final class MakeRegistrationForm extends AbstractMaker
6666
private $formTypeRenderer;
6767
private $router;
6868
private $doctrineHelper;
69-
private $phpCompatUtil;
7069

7170
private $userClass;
7271
private $usernameField;
@@ -82,13 +81,12 @@ final class MakeRegistrationForm extends AbstractMaker
8281
private $redirectRouteName;
8382
private $addUniqueEntityConstraint;
8483

85-
public function __construct(FileManager $fileManager, FormTypeRenderer $formTypeRenderer, RouterInterface $router, DoctrineHelper $doctrineHelper, PhpCompatUtil $phpCompatUtil)
84+
public function __construct(FileManager $fileManager, FormTypeRenderer $formTypeRenderer, RouterInterface $router, DoctrineHelper $doctrineHelper)
8685
{
8786
$this->fileManager = $fileManager;
8887
$this->formTypeRenderer = $formTypeRenderer;
8988
$this->router = $router;
9089
$this->doctrineHelper = $doctrineHelper;
91-
$this->phpCompatUtil = $phpCompatUtil;
9290
}
9391

9492
public static function getCommandName(): string
@@ -321,7 +319,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
321319
'user_class_name' => $userClassNameDetails->getShortName(),
322320
'password_field' => $this->passwordField,
323321
'will_verify_email' => $this->willVerifyEmail,
324-
'email_verifier_details' => new TemplateClassDetails($verifyEmailServiceClassNameDetails->getFullName(), $this->phpCompatUtil->canUseTypedProperties()),
322+
'email_verifier_class' => $generator->createClassHelper($verifyEmailServiceClassNameDetails->getFullName()),
325323
'verify_email_anonymously' => $this->verifyEmailAnonymously,
326324
'from_email' => $this->fromEmailAddress,
327325
'from_email_name' => $this->fromEmailName,
@@ -330,7 +328,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
330328
'authenticator_full_class_name' => $this->autoLoginAuthenticator,
331329
'firewall_name' => $this->firewallName,
332330
'redirect_route_name' => $this->redirectRouteName,
333-
'password_details' => new TemplateClassDetails($passwordHasher, $this->phpCompatUtil->canUseTypedProperties()),
331+
'password_class' => $generator->createClassHelper($passwordHasher),
334332
'use_password_hasher' => UserPasswordHasherInterface::class === $passwordHasher,
335333
],
336334
$userRepoVars

src/Resources/config/makers.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
<argument type="service" id="maker.renderer.form_type_renderer" />
7373
<argument type="service" id="router" />
7474
<argument type="service" id="maker.doctrine_helper" />
75-
<argument type="service" id="maker.php_compat_util" />
7675
<tag name="maker.command" />
7776
</service>
7877

src/Resources/skeleton/registration/RegistrationController.tpl.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?>
88
{
99
<?php if ($will_verify_email): ?>
10-
<?= $email_verifier_details->getPropertyStatement() ?>
10+
<?= $email_verifier_class->getPropertyStatement() ?>
1111

12-
public function __construct(<?= $email_verifier_details->getMethodArgument() ?>)
12+
public function __construct(<?= $email_verifier_class->getMethodArgument() ?>)
1313
{
14-
<?= $email_verifier_details->getConstructorArgument(true, false) ?>
14+
<?= $email_verifier_class->getConstructorArgument(true, false) ?>
1515
}
1616

1717
<?php endif; ?>
@@ -22,7 +22,7 @@ public function __construct(<?= $email_verifier_details->getMethodArgument() ?>)
2222
* @Route("<?= $route_path ?>", name="<?= $route_name ?>")
2323
*/
2424
<?php } ?>
25-
public function register(Request $request, <?= $password_details->getMethodArgument() ?><?= $authenticator_full_class_name ? sprintf(', GuardAuthenticatorHandler $guardHandler, %s $authenticator', $authenticator_class_name) : '' ?>): Response
25+
public function register(Request $request, <?= $password_class->getMethodArgument() ?><?= $authenticator_full_class_name ? sprintf(', GuardAuthenticatorHandler $guardHandler, %s $authenticator', $authenticator_class_name) : '' ?>): Response
2626
{
2727
$user = new <?= $user_class_name ?>();
2828
$form = $this->createForm(<?= $form_class_name ?>::class, $user);
@@ -32,9 +32,9 @@ public function register(Request $request, <?= $password_details->getMethodArgum
3232
// encode the plain password
3333
$user->set<?= ucfirst($password_field) ?>(
3434
<?php if ($use_password_hasher) : ?>
35-
<?= $password_details->getVariable() ?>->hashPassword(
35+
<?= $password_class->getVariable() ?>->hashPassword(
3636
<?php else: ?>
37-
<?= $password_details->getVariable() ?>->encodePassword(
37+
<?= $password_class->getVariable() ?>->encodePassword(
3838
<?php endif; ?>
3939
$user,
4040
$form->get('plainPassword')->getData()
@@ -47,7 +47,7 @@ public function register(Request $request, <?= $password_details->getMethodArgum
4747
<?php if ($will_verify_email): ?>
4848

4949
// generate a signed url and email it to the user
50-
<?= $email_verifier_details->getProperty() ?>->sendEmailConfirmation('app_verify_email', $user,
50+
<?= $email_verifier_class->getProperty() ?>->sendEmailConfirmation('app_verify_email', $user,
5151
(new TemplatedEmail())
5252
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
5353
->to($user-><?= $email_getter ?>())
@@ -108,7 +108,7 @@ public function verifyUserEmail(Request $request<?= $verify_email_anonymously ?
108108

109109
// validate email confirmation link, sets User::isVerified=true and persists
110110
try {
111-
<?= $email_verifier_details->getProperty() ?>->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
111+
<?= $email_verifier_class->getProperty() ?>->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
112112
} catch (VerifyEmailExceptionInterface $exception) {
113113
$this->addFlash('verify_email_error', $exception->getReason());
114114

0 commit comments

Comments
 (0)