-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRepository.php
More file actions
84 lines (72 loc) · 2.43 KB
/
UserRepository.php
File metadata and controls
84 lines (72 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
use function get_class;
/**
* @extends ServiceEntityRepository<User>
*
* @method User|null find( $id, $lockMode = null, $lockVersion = null )
* @method User|null findOneBy( array $criteria, array $orderBy = null )
* @method User[] findAll()
* @method User[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
*/
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct( ManagerRegistry $registry )
{
parent::__construct( $registry, User::class );
}
public function remove( User $entity, bool $flush = false ): void
{
$this->getEntityManager()->remove( $entity );
if ( $flush ) {
$this->getEntityManager()->flush();
}
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
*/
public function upgradePassword( PasswordAuthenticatedUserInterface $user, string $newHashedPassword ): void
{
if ( ! $user instanceof User ) {
throw new UnsupportedUserException( sprintf( 'Instances of "%s" are not supported.', get_class( $user ) ) );
}
$user->setPassword( $newHashedPassword );
$this->save( $user, true );
}
public function save( User $entity, bool $flush = false ): void
{
$this->getEntityManager()->persist( $entity );
if ( $flush ) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return User[] Returns an array of User objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?User
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}