You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserRepository.php 2.5KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Lc\SovBundle\Repository\User;
  3. use Lc\SovBundle\Model\User\UserInterface;
  4. use Lc\SovBundle\Repository\AbstractRepository;
  5. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  6. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface as SfUserInterface;
  8. /**
  9. * @method UserInterface|null find($id, $lockMode = null, $lockVersion = null)
  10. * @method UserInterface|null findOneBy(array $criteria, array $orderBy = null)
  11. * @method UserInterface[] findAll()
  12. * @method UserInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13. */
  14. class UserRepository extends AbstractRepository implements PasswordUpgraderInterface
  15. {
  16. public function getInterfaceClass()
  17. {
  18. return UserInterface::class;
  19. }
  20. /**
  21. * Used to upgrade (rehash) the user's password automatically over time.
  22. */
  23. public function upgradePassword(SfUserInterface $user, string $newEncodedPassword): void
  24. {
  25. if (!$user instanceof SfUserInterface) {
  26. throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
  27. }
  28. $user->setPassword($newEncodedPassword);
  29. $this->_em->persist($user);
  30. $this->_em->flush();
  31. }
  32. public function findByRole($role) {
  33. return $this->createQueryBuilder('u')
  34. ->andWhere('u.roles LIKE :role')
  35. ->setParameter('role', '%'.$role.'%')
  36. ->getQuery()
  37. ->getResult();
  38. }
  39. // /**
  40. // * @return User[] Returns an array of User objects
  41. // */
  42. /*
  43. public function findByExampleField($value)
  44. {
  45. return $this->createQueryBuilder('u')
  46. ->andWhere('u.exampleField = :val')
  47. ->setParameter('val', $value)
  48. ->orderBy('u.id', 'ASC')
  49. ->setMaxResults(10)
  50. ->getQuery()
  51. ->getResult()
  52. ;
  53. }
  54. */
  55. /*
  56. public function findOneBySomeField($value): ?User
  57. {
  58. return $this->createQueryBuilder('u')
  59. ->andWhere('u.exampleField = :val')
  60. ->setParameter('val', $value)
  61. ->getQuery()
  62. ->getOneOrNullResult()
  63. ;
  64. }
  65. */
  66. }