Skip to content

Commit e32fcc0

Browse files
committed
Added UserLoaderInterface for loading users through Doctrine.
1 parent 3146062 commit e32fcc0

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ public function loadUserByUsername($username)
5454
if (null !== $this->property) {
5555
$user = $this->repository->findOneBy(array($this->property => $username));
5656
} else {
57-
if (!$this->repository instanceof UserProviderInterface) {
58-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository)));
57+
if (!$this->repository instanceof UserLoaderInterface) {
58+
if (!$this->repository instanceof UserProviderInterface) {
59+
throw new \InvalidArgumentException(sprintf(
60+
'The Doctrine repository "%s" must implement UserLoaderInterface.',
61+
get_class($this->repository)
62+
));
63+
}
64+
65+
@trigger_error('Implementing loadUserByUsername from Symfony\Component\Security\Core\User\UserProviderInterface is deprecated since version 2.8 and will be removed in 3.0. Implement the Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface instead.', E_USER_DEPRECATED);
5966
}
6067

6168
$user = $this->repository->loadUserByUsername($username);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Security\User;
13+
14+
use Symfony\Component\Security\Core\User\UserInterface;
15+
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
16+
17+
/**
18+
* Represents a class that loads UserInterface objects from Doctrine source for the authentication system.
19+
*
20+
* This interface is meant to facilitate the loading of a User from Doctrine source using a custom method.
21+
* If you want to implement your own logic of retrieving the user from Doctrine your repository should implement this
22+
* interface.
23+
*
24+
* @see UserInterface
25+
*
26+
* @author Fabien Potencier <fabien@symfony.com>
27+
*/
28+
interface UserLoaderInterface
29+
{
30+
/**
31+
* Loads the user for the given username.
32+
*
33+
* This method must throw UsernameNotFoundException if the user is not
34+
* found.
35+
*
36+
* @param string $username The username
37+
*
38+
* @return UserInterface
39+
*
40+
* @see UsernameNotFoundException
41+
*
42+
* @throws UsernameNotFoundException if the user is not found
43+
*/
44+
public function loadUserByUsername($username);
45+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy