Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UserRepository.php 1.2KB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839
  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->persist($user);
  24. $this->_em->flush();
  25. }
  26. public function findByRole($role) {
  27. return $this->createQueryBuilder('u')
  28. ->andWhere('u.roles LIKE :role')
  29. ->setParameter('role', '%'.$role.'%')
  30. ->getQuery()
  31. ->getResult();
  32. }
  33. }