initial commit
This commit is contained in:
parent
25445e5cc0
commit
f30e468456
|
@ -6,8 +6,8 @@ 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 Symfony\Component\Security\Core\User\UserInterface;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
|
@ -20,20 +20,40 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
|
|||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
parent::__construct(registry: $registry, entityClass: User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function add(User $entity, bool $flush = true): void
|
||||
{
|
||||
$this->_em->persist(entity: $entity);
|
||||
if ($flush) {
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function remove(User $entity, bool $flush = true): void
|
||||
{
|
||||
$this->_em->remove(entity: $entity);
|
||||
if ($flush) {
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to upgrade (rehash) the user's password automatically over time.
|
||||
*/
|
||||
public function upgradePassword(UserInterface $user, string $newHashedPassword): void
|
||||
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)));
|
||||
throw new UnsupportedUserException(message: sprintf('Instances of "%s" are not supported.', get_class(object: $user)));
|
||||
}
|
||||
|
||||
$user->setPassword($newHashedPassword);
|
||||
$this->_em->persist($user);
|
||||
$user->setPassword(password: $newHashedPassword);
|
||||
$this->_em->persist(entity: $user);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue