Skip to content

Commit d2b85d5

Browse files
committed
replace helper w/ ClassNameDetailsObject
1 parent 52da443 commit d2b85d5

File tree

5 files changed

+25
-105
lines changed

5 files changed

+25
-105
lines changed

src/Generator.php

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

160-
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix);
160+
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix, $this->phpCompatUtil->canUseTypedProperties());
161161
}
162162

163163
/**

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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
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; ?>
1818
<?= $generator->generateRouteForControllerMethod($route_path, $route_name) ?>
19-
public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder<?= $authenticator_full_class_name ? sprintf(', GuardAuthenticatorHandler $guardHandler, %s $authenticator', $authenticator_class_name) : '' ?>): Response
19+
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
2020
{
2121
$user = new <?= $user_class_name ?>();
2222
$form = $this->createForm(<?= $form_class_name ?>::class, $user);
@@ -25,12 +25,7 @@ public function register(Request $request, UserPasswordEncoderInterface $passwor
2525
if ($form->isSubmitted() && $form->isValid()) {
2626
// encode the plain password
2727
$user->set<?= ucfirst($password_field) ?>(
28-
$passwordEncoder->encodePassword(
29-
<?php if ($use_password_hasher) : ?>
30-
<?= $password_class->getVariable() ?>->hashPassword(
31-
<?php else: ?>
32-
<?= $password_class->getVariable() ?>->encodePassword(
33-
<?php endif; ?>
28+
<?= $password_variable_name ?>-><?= $use_password_hasher ? 'hashPassword' : 'encodePassword' ?>(
3429
$user,
3530
$form->get('plainPassword')->getData()
3631
)
@@ -42,7 +37,7 @@ public function register(Request $request, UserPasswordEncoderInterface $passwor
4237
<?php if ($will_verify_email): ?>
4338

4439
// generate a signed url and email it to the user
45-
<?= $email_verifier_class->getProperty() ?>->sendEmailConfirmation('app_verify_email', $user,
40+
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
4641
(new TemplatedEmail())
4742
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
4843
->to($user-><?= $email_getter ?>())
@@ -97,7 +92,7 @@ public function verifyUserEmail(Request $request<?= $verify_email_anonymously ?
9792

9893
// validate email confirmation link, sets User::isVerified=true and persists
9994
try {
100-
<?= $email_verifier_class->getProperty() ?>->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
95+
$this->emailVerifier->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
10196
} catch (VerifyEmailExceptionInterface $exception) {
10297
$this->addFlash('verify_email_error', $exception->getReason());
10398

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)