Skip to content

Commit 35db9d3

Browse files
Merge branch '7.4' into 8.0
* 7.4: [DoctrineBridge] Make `EntityUserProvider`s pass attributes to their loader [WebProfilerBundle][HttpKernel] Display runner class in the profiler toolbar
2 parents b7d60b9 + 863578f commit 35db9d3

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Security/User/EntityUserProvider.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Doctrine\Persistence\Proxy;
1919
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
2020
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
21+
use Symfony\Component\Security\Core\User\AttributesBasedUserProviderInterface;
2122
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2223
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2324
use Symfony\Component\Security\Core\User\UserInterface;
@@ -33,9 +34,9 @@
3334
*
3435
* @template TUser of UserInterface
3536
*
36-
* @template-implements UserProviderInterface<TUser>
37+
* @template-implements AttributesBasedUserProviderInterface<TUser>
3738
*/
38-
class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInterface
39+
class EntityUserProvider implements AttributesBasedUserProviderInterface, PasswordUpgraderInterface
3940
{
4041
private string $class;
4142

@@ -47,7 +48,7 @@ public function __construct(
4748
) {
4849
}
4950

50-
public function loadUserByIdentifier(string $identifier): UserInterface
51+
public function loadUserByIdentifier(string $identifier, ?array $attributes = null): UserInterface
5152
{
5253
$repository = $this->getRepository();
5354
if (null !== $this->property) {
@@ -57,7 +58,11 @@ public function loadUserByIdentifier(string $identifier): UserInterface
5758
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)));
5859
}
5960

60-
$user = $repository->loadUserByIdentifier($identifier);
61+
if (null === $attributes) {
62+
$user = $repository->loadUserByIdentifier($identifier);
63+
} else {
64+
$user = $repository->loadUserByIdentifier($identifier, $attributes);
65+
}
6166
}
6267

6368
if (null === $user) {

Tests/Security/User/EntityUserProviderTest.php

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

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

0 commit comments

Comments
 (0)