Skip to content

Commit 39fd781

Browse files
Merge branch '6.4' into 7.3
* 6.4: [DoctrineBridge] Make `EntityUserProvider`s pass attributes to their loader
2 parents b085683 + dacc412 commit 39fd781

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Security/User/EntityUserProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public function __construct(
4747
) {
4848
}
4949

50-
public function loadUserByIdentifier(string $identifier): UserInterface
50+
/**
51+
* @param ?array $attributes
52+
*/
53+
public function loadUserByIdentifier(string $identifier/* , ?array $attributes = null */): UserInterface
5154
{
5255
$repository = $this->getRepository();
5356
if (null !== $this->property) {
@@ -57,7 +60,11 @@ public function loadUserByIdentifier(string $identifier): UserInterface
5760
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)));
5861
}
5962

60-
$user = $repository->loadUserByIdentifier($identifier);
63+
if (null === $attributes = \func_num_args() > 1 ? func_get_arg(1) : null) {
64+
$user = $repository->loadUserByIdentifier($identifier);
65+
} else {
66+
$user = $repository->loadUserByIdentifier($identifier, $attributes);
67+
}
6168
}
6269

6370
if (null === $user) {

Tests/Security/User/EntityUserProviderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,24 @@ public function testLoadUserByIdentifierShouldLoadUserWhenProperInterfaceProvide
172172
$provider->loadUserByIdentifier('name');
173173
}
174174

175+
public function testLoadUserByIdentifierShouldPassAttributesToTheUserLoader()
176+
{
177+
$repository = $this->createMock(UserLoaderRepository::class);
178+
$repository->expects($this->once())
179+
->method('loadUserByIdentifier')
180+
->with('name', ['foo' => 'bar'])
181+
->willReturn(
182+
$this->createMock(UserInterface::class)
183+
);
184+
185+
$provider = new EntityUserProvider(
186+
$this->getManager($this->getObjectManager($repository)),
187+
'Symfony\Bridge\Doctrine\Tests\Fixtures\User'
188+
);
189+
190+
$provider->loadUserByIdentifier('name', ['foo' => 'bar']);
191+
}
192+
175193
public function testLoadUserByIdentifierShouldDeclineInvalidInterface()
176194
{
177195
$repository = $this->createMock(ObjectRepository::class);

0 commit comments

Comments
 (0)