Skip to content

Commit c3d4046

Browse files
wouterjjrushlow
authored andcommitted
Still implement deprecated username method
This updates the makers for symfony/symfony#41493
1 parent 4edd87e commit c3d4046

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Resources/skeleton/security/UserProvider.tpl.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public function <?= $uses_user_identifier ? 'loadUserByIdentifier($identifier)'
2828
throw new \Exception('TODO: fill in <?= $uses_user_identifier ? 'loadUserByIdentifier()' : 'loadUserByUsername()' ?> inside '.__FILE__);
2929
}
3030

31+
<?php if ($uses_user_identifier) : ?>
32+
/**
33+
* @deprecated since Symfony 5.3, loadUserByIdentifier() is used instead
34+
*/
35+
public function loadUserByUsername($username): UserInterface
36+
{
37+
return $this->loadUserByIdentifier($username);
38+
}
39+
<?php endif ?>
40+
3141
/**
3242
* Refreshes the user after being reloaded from the session.
3343
*

src/Security/UserClassBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
103103
// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier()
104104
if (class_exists(InMemoryUser::class)) {
105105
$getterIdentifierName = 'getUserIdentifier';
106+
107+
// also add the deprecated getUsername method
108+
$manipulator->addAccessorMethod(
109+
$userClassConfig->getIdentityPropertyName(),
110+
'getUsername',
111+
'string',
112+
false,
113+
['@deprecated since Symfony 5.3, use getUserIdentifier instead'],
114+
true
115+
);
106116
}
107117

108118
// define getUsername (if it was defined above, this will override)

0 commit comments

Comments
 (0)