Skip to content

Commit 5ee7fc0

Browse files
committed
replace helper w/ ClassNameDetailsObject
1 parent e137664 commit 5ee7fc0

File tree

5 files changed

+25
-104
lines changed

5 files changed

+25
-104
lines changed

src/Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st
154154
$fullNamespacePrefix = $this->fileManager->getNamespacePrefixForClass($className);
155155
}
156156

157-
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix);
157+
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix, $this->phpCompatUtil->canUseTypedProperties());
158158
}
159159

160160
/**

src/Maker/MakeRegistrationForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
317317
'user_class_name' => $userClassNameDetails->getShortName(),
318318
'password_field' => $this->passwordField,
319319
'will_verify_email' => $this->willVerifyEmail,
320-
'email_verifier_class' => $generator->createClassHelper($verifyEmailServiceClassNameDetails->getFullName()),
320+
'email_verifier_class_details' => $verifyEmailServiceClassNameDetails,
321321
'verify_email_anonymously' => $this->verifyEmailAnonymously,
322322
'from_email' => $this->fromEmailAddress,
323323
'from_email_name' => $this->fromEmailName,
@@ -326,7 +326,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
326326
'authenticator_full_class_name' => $this->autoLoginAuthenticator,
327327
'firewall_name' => $this->firewallName,
328328
'redirect_route_name' => $this->redirectRouteName,
329-
'password_class' => $generator->createClassHelper($passwordHasher),
329+
'password_class_details' => ($passwordClassDetails = $generator->createClassNameDetails($passwordHasher, '\\')),
330+
'password_variable_name' => sprintf('$%s', lcfirst($passwordClassDetails->getShortName())),
330331
'use_password_hasher' => UserPasswordHasherInterface::class === $passwordHasher,
331332
],
332333
$userRepoVars

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

Lines changed: 7 additions & 11 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_class->getPropertyStatement() ?>
10+
private <?= $email_verifier_class_details->getPropertyType() ?>$emailVerifier;
1111

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

1717
<?php endif; ?>
@@ -22,7 +22,7 @@ public function __construct(<?= $email_verifier_class->getMethodArgument() ?>)
2222
* @Route("<?= $route_path ?>", name="<?= $route_name ?>")
2323
*/
2424
<?php } ?>
25-
public function register(Request $request, <?= $password_class->getMethodArgument() ?><?= $authenticator_full_class_name ? sprintf(', GuardAuthenticatorHandler $guardHandler, %s $authenticator', $authenticator_class_name) : '' ?>): Response
25+
public function register(Request $request, <?= $password_class_details->getShortName() ?> <?= $password_variable_name ?><?= $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);
@@ -31,11 +31,7 @@ public function register(Request $request, <?= $password_class->getMethodArgumen
3131
if ($form->isSubmitted() && $form->isValid()) {
3232
// encode the plain password
3333
$user->set<?= ucfirst($password_field) ?>(
34-
<?php if ($use_password_hasher) : ?>
35-
<?= $password_class->getVariable() ?>->hashPassword(
36-
<?php else: ?>
37-
<?= $password_class->getVariable() ?>->encodePassword(
38-
<?php endif; ?>
34+
<?= $password_variable_name ?>-><?= $use_password_hasher ? 'hashPassword' : 'encodePassword' ?>(
3935
$user,
4036
$form->get('plainPassword')->getData()
4137
)
@@ -47,7 +43,7 @@ public function register(Request $request, <?= $password_class->getMethodArgumen
4743
<?php if ($will_verify_email): ?>
4844

4945
// generate a signed url and email it to the user
50-
<?= $email_verifier_class->getProperty() ?>->sendEmailConfirmation('app_verify_email', $user,
46+
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
5147
(new TemplatedEmail())
5248
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
5349
->to($user-><?= $email_getter ?>())
@@ -108,7 +104,7 @@ public function verifyUserEmail(Request $request<?= $verify_email_anonymously ?
108104

109105
// validate email confirmation link, sets User::isVerified=true and persists
110106
try {
111-
<?= $email_verifier_class->getProperty() ?>->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
107+
$this->emailVerifier->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
112108
} catch (VerifyEmailExceptionInterface $exception) {
113109
$this->addFlash('verify_email_error', $exception->getReason());
114110

src/Util/ClassNameDetails.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
final class ClassNameDetails
1717
{
1818
private $fullClassName;
19-
2019
private $namespacePrefix;
21-
2220
private $suffix;
21+
private $usesTypedProperties;
2322

24-
public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null)
23+
public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null, ?bool $usesTypedProperties = null)
2524
{
2625
$this->fullClassName = $fullClassName;
2726
$this->namespacePrefix = trim($namespacePrefix, '\\');
2827
$this->suffix = $suffix;
28+
$this->usesTypedProperties = $usesTypedProperties;
29+
30+
// @TODO throw deprecation if bool not passed....
2931
}
3032

3133
public function getFullName(): string
@@ -38,6 +40,15 @@ public function getShortName(): string
3840
return Str::getShortClassName($this->fullClassName);
3941
}
4042

43+
public function getPropertyType(): ?string
44+
{
45+
if (!$this->usesTypedProperties) {
46+
return null;
47+
}
48+
49+
return sprintf('%s ', $this->getShortName());
50+
}
51+
4152
/**
4253
* Returns the original class name the user entered (after
4354
* being cleaned up).

src/Util/TemplateClassHelper.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)