8000 [DoctrineBridge] Rename UserLoaderInterface::loadUserByUsername() to … · symfony/symfony@45fd033 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45fd033

Browse files
committed
[DoctrineBridge] Rename UserLoaderInterface::loadUserByUsername() to loadUserByIdentifier()
1 parent 749b6c1 commit 45fd033

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

UPGRADE-5.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Asset
99
DoctrineBridge
1010
--------------
1111

12+
* Deprecate `UserLoaderInterface::loadUserByUsername()` in favor of `UserLoaderInterface::loadUserByIdentifier()
1213
* Remove `UuidV*Generator` classes
1314

1415
DomCrawler

UPGRADE-6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Asset
66

77
* Removed `RemoteJsonManifestVersionStrategy`, use `JsonManifestVersionStrategy` instead.
88

9+
DoctrineBridge
10+
--------------
11+
12+
* Remove `UserLoaderInterface::loadUserByUsername()` in favor of `UserLoaderInterface::loadUserByIdentifier()
13+
914
Config
1015
------
1116

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.3
55
---
66

7+
* Deprecate `UserLoaderInterface::loadUserByUsername()` in favor of `UserLoaderInterface::loadUserByIdentifier()
78
* Deprecate `DoctrineTestHelper` and `TestRepositoryFactory`
89
* [BC BREAK] Remove `UuidV*Generator` classes
910
* Add `UuidGenerator`

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ public function loadUserByIdentifier(string $identifier): UserInterface
6666
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_debug_type($repository)));
6767
}
6868

69-
$user = $repository->loadUserByUsername($identifier);
69+
// @deprecated since 5.3, change to $repository->loadUserByIdentifier() in 6.0
70+
if (method_exists($repository, 'loadUserByIdentifier')) {
71+
$user = $repository->loadUserByIdentifier($identifier);
72+
} else {
73+
trigger_deprecation('symfony/doctrine-bridge', '5.3', 'Not implementing method "loadUserByIdentifier()" in user loader "%s" is deprecated. This method will replace "loadUserByUsername()" in Symfony 6.0.', get_debug_type($repository));
74+
75+
$user = $repository->loadUserByUsername($identifier);
76+
}
7077
}
7178

7279
if (null === $user) {

src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
*
2323
* @see UserInterface
2424
*
25+
* @method UserInterface|null loadUserByIdentifier(string $identifier) loads the user for the given user identifier (e.g. username or email).
26+
* This method must return null if the user is not found.
27+
*
2528
* @author Michal Trojanowski <michal@kmt-studio.pl>
2629
*/
2730
interface UserLoaderInterface
2831
{
29-
/**
30-
* Loads the user for the given username.
31-
*
32-
* This method must return null if the user is not found.
33-
*
34-
* @return UserInterface|null
35-
*/
36-
public function loadUserByUsername(string $username);
3732
}

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
7070
$repository = $this->createMock(UserLoaderRepository::class);
7171
$repository
7272
->expects($this->once())
73-
->method('loadUserByUsername')
73+
->method('loadUserByIdentifier')
7474
->with('user1')
7575
->willReturn($user);
7676

@@ -153,7 +153,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
153153
{
154154
$repository = $this->createMock(UserLoaderRepository::class);
155155
$repository->expects($this->once())
156-
->method('loadUserByUsername')
156+
->method('loadUserByIdentifier')
157157
->with('name')
158158
->willReturn(
159159
$this->createMock(UserInterface::class)
@@ -231,6 +231,7 @@ private function createSchema($em)
231231

232232
abstract class UserLoaderRepository implements ObjectRepository, UserLoaderInterface
233233
{
234+
abstract public function loadUserByIdentifier(string $identifier): ?UserInterface;
234235
}
235236

236237
abstract class PasswordUpgraderRepository implements ObjectRepository, PasswordUpgraderInterface

0 commit comments

Comments
 (0)
0