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 1.2KB

3 yıl önce
3 yıl önce
3 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Lc\SovBundle\Repository\User;
  3. use App\Entity\User\User;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Lc\SovBundle\Repository\AbstractRepository;
  6. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  7. use Symfony\Component\Security\Core\User\UserInterface as SfUserInterface;
  8. class UserRepository extends AbstractRepository
  9. {
  10. public function __construct(ManagerRegistry $registry)
  11. {
  12. parent::__construct($registry, User::class);
  13. }
  14. /**
  15. * Used to upgrade (rehash) the user's password automatically over time.
  16. */
  17. public function upgradePassword(SfUserInterface $user, string $newEncodedPassword): void
  18. {
  19. if (!$user instanceof SfUserInterface) {
  20. throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
  21. }
  22. $user->setPassword($newEncodedPassword);
  23. $this->_em->update($user);
  24. $this->_em->flush();
  25. }
  26. public function findByRole($role)
  27. {
  28. return $this->createQueryBuilder('u')
  29. ->andWhere('u.roles LIKE :role')
  30. ->setParameter('role', '%' . $role . '%')
  31. ->getQuery()
  32. ->getResult();
  33. }
  34. }