@@ 12-55 (lines=44) @@ | ||
9 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
10 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
11 | ||
12 | class ObjectUserEmailProvider implements UserProviderInterface |
|
13 | { |
|
14 | /** @var UserRepositoryCollection */ |
|
15 | private $userRepositoryCollection; |
|
16 | ||
17 | /** |
|
18 | * @param UserRepositoryCollection $userRepositoryCollection |
|
19 | */ |
|
20 | public function __construct(UserRepositoryCollection $userRepositoryCollection) |
|
21 | { |
|
22 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
23 | } |
|
24 | ||
25 | public function loadUserByUsername($username) |
|
26 | { |
|
27 | foreach ($this->userRepositoryCollection->all() as $repository) { |
|
28 | $user = $repository->findByEmailAddress($username); |
|
29 | ||
30 | if ($user instanceof User) { |
|
31 | return $user; |
|
32 | } |
|
33 | } |
|
34 | ||
35 | throw new UsernameNotFoundException( |
|
36 | sprintf('Username "%s" does not exist.', $username) |
|
37 | ); |
|
38 | } |
|
39 | ||
40 | public function refreshUser(UserInterface $user) |
|
41 | { |
|
42 | if (!$this->supportsClass(get_class($user))) { |
|
43 | throw new UnsupportedUserException( |
|
44 | sprintf('Instances of "%s" are not supported.', get_class($user)) |
|
45 | ); |
|
46 | } |
|
47 | ||
48 | return $this->loadUserByUsername($user->getUsername()); |
|
49 | } |
|
50 | ||
51 | public function supportsClass($class) |
|
52 | { |
|
53 | return $this->userRepositoryCollection->supportsClass($class); |
|
54 | } |
|
55 | } |
|
56 |
@@ 12-55 (lines=44) @@ | ||
9 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
10 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
11 | ||
12 | class ObjectUserProvider implements UserProviderInterface |
|
13 | { |
|
14 | /** @var UserRepositoryCollection */ |
|
15 | private $userRepositoryCollection; |
|
16 | ||
17 | /** |
|
18 | * @param UserRepositoryCollection $userRepositoryCollection |
|
19 | */ |
|
20 | public function __construct(UserRepositoryCollection $userRepositoryCollection) |
|
21 | { |
|
22 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
23 | } |
|
24 | ||
25 | public function loadUserByUsername($username) |
|
26 | { |
|
27 | foreach ($this->userRepositoryCollection->all() as $repository) { |
|
28 | $user = $repository->findByUsername($username); |
|
29 | ||
30 | if ($user instanceof User) { |
|
31 | return $user; |
|
32 | } |
|
33 | } |
|
34 | ||
35 | throw new UsernameNotFoundException( |
|
36 | sprintf('Username "%s" does not exist.', $username) |
|
37 | ); |
|
38 | } |
|
39 | ||
40 | public function refreshUser(UserInterface $user) |
|
41 | { |
|
42 | if (!$this->supportsClass(get_class($user))) { |
|
43 | throw new UnsupportedUserException( |
|
44 | sprintf('Instances of "%s" are not supported.', get_class($user)) |
|
45 | ); |
|
46 | } |
|
47 | ||
48 | return $this->loadUserByUsername($user->getUsername()); |
|
49 | } |
|
50 | ||
51 | public function supportsClass($class) |
|
52 | { |
|
53 | return $this->userRepositoryCollection->supportsClass($class); |
|
54 | } |
|
55 | } |
|
56 |