Skip to content

Commit

Permalink
Still implement deprecated username method
Browse files Browse the repository at this point in the history
This updates the makers for symfony/symfony#41493
  • Loading branch information
wouterj authored and jrushlow committed Jun 8, 2021
1 parent 4edd87e commit c3d4046
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Resources/skeleton/security/UserProvider.tpl.php
Expand Up @@ -28,6 +28,16 @@ public function <?= $uses_user_identifier ? 'loadUserByIdentifier($identifier)'
throw new \Exception('TODO: fill in <?= $uses_user_identifier ? 'loadUserByIdentifier()' : 'loadUserByUsername()' ?> inside '.__FILE__);
}

<?php if ($uses_user_identifier) : ?>
/**
* @deprecated since Symfony 5.3, loadUserByIdentifier() is used instead
*/
public function loadUserByUsername($username): UserInterface
{
return $this->loadUserByIdentifier($username);
}
<?php endif ?>

/**
* Refreshes the user after being reloaded from the session.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Security/UserClassBuilder.php
Expand Up @@ -103,6 +103,16 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier()
if (class_exists(InMemoryUser::class)) {
$getterIdentifierName = 'getUserIdentifier';

// also add the deprecated getUsername method
$manipulator->addAccessorMethod(
$userClassConfig->getIdentityPropertyName(),
'getUsername',
'string',
false,
['@deprecated since Symfony 5.3, use getUserIdentifier instead'],
true
);
}

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

0 comments on commit c3d4046

Please sign in to comment.