1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\User; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
6
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Security\PasswordResetToken; |
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User as UserInterface; |
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository as UserRepositoryInterface; |
9
|
|
|
|
10
|
|
|
abstract class UserRepository extends EntityRepository implements UserRepositoryInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param UserInterface $user |
14
|
|
|
*/ |
15
|
|
|
public function add(UserInterface $user) |
16
|
|
|
{ |
17
|
|
|
$this->getEntityManager()->persist($user); |
18
|
|
|
$this->getEntityManager()->flush(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $username |
23
|
|
|
* |
24
|
|
|
* @return null|UserInterface |
25
|
|
|
*/ |
26
|
|
|
public function findByUsername($username) |
27
|
|
|
{ |
28
|
|
|
return $this->findOneBy(['username' => $username]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $emailAddress |
33
|
|
|
* |
34
|
|
|
* @return UserInterface|null |
35
|
|
|
*/ |
36
|
|
|
public function findByEmailAddress($emailAddress) |
37
|
|
|
{ |
38
|
|
|
return $this->findOneBy(['email' => $emailAddress]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $class |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
abstract public function supportsClass($class); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param UserInterface $user |
50
|
|
|
*/ |
51
|
|
|
public function save(UserInterface $user) |
52
|
|
|
{ |
53
|
|
|
$this->getEntityManager()->flush(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param UserInterface $user |
58
|
|
|
*/ |
59
|
|
|
public function delete(UserInterface $user) |
60
|
|
|
{ |
61
|
|
|
$this->getEntityManager()->remove($user); |
62
|
|
|
$this->getEntityManager()->flush(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param PasswordResetToken $token |
67
|
|
|
* |
68
|
|
|
* @return null|UserInterface |
69
|
|
|
*/ |
70
|
|
|
public function findByPasswordResetToken(PasswordResetToken $token) |
71
|
|
|
{ |
72
|
|
|
return $this->findOneBy(['passwordResetToken' => $token->getToken()]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|