mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 02:25:00 +00:00
Refactor code to directly use Doctrine's ManagerRegistry
Replaced most of the invocations of getDoctrine()->getManager() with ManagerRegistry->getManager(), and added ManagerRegistry injection to controllers where needed. This is part of an ongoing effort to improve code clarity, and avoid unnecessary method chaining in various parts of the codebase.
This commit is contained in:
@@ -40,7 +40,7 @@ final class PasswordController extends AbstractController
|
||||
/**
|
||||
* PasswordController constructor.
|
||||
*/
|
||||
public function __construct(private readonly LoggerInterface $chillLogger, private readonly UserPasswordEncoderInterface $passwordEncoder, private readonly RecoverPasswordHelper $recoverPasswordHelper, private readonly TokenManager $tokenManager, private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher, private readonly ChillSecurity $security) {}
|
||||
public function __construct(private readonly LoggerInterface $chillLogger, private readonly UserPasswordEncoderInterface $passwordEncoder, private readonly RecoverPasswordHelper $recoverPasswordHelper, private readonly TokenManager $tokenManager, private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher, private readonly ChillSecurity $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
@@ -68,7 +68,7 @@ final class PasswordController extends AbstractController
|
||||
$hash = $query->getAlnum(TokenManager::HASH);
|
||||
$token = $query->getAlnum(TokenManager::TOKEN);
|
||||
$timestamp = $query->getAlnum(TokenManager::TIMESTAMP);
|
||||
$user = $this->getDoctrine()->getRepository(User::class)
|
||||
$user = $this->managerRegistry->getRepository(User::class)
|
||||
->findOneByUsernameCanonical($username);
|
||||
|
||||
if (null === $user) {
|
||||
@@ -107,7 +107,7 @@ final class PasswordController extends AbstractController
|
||||
]
|
||||
);
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute('password_request_recover_changed');
|
||||
}
|
||||
@@ -137,7 +137,7 @@ final class PasswordController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var \Doctrine\ORM\QueryBuilder $qb */
|
||||
$qb = $this->getDoctrine()->getManager()
|
||||
$qb = $this->managerRegistry->getManager()
|
||||
->createQueryBuilder();
|
||||
$qb->select('u')
|
||||
->from(User::class, 'u')
|
||||
@@ -236,7 +236,7 @@ final class PasswordController extends AbstractController
|
||||
|
||||
$user->setPassword($this->passwordEncoder->encodePassword($user, $password));
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('Password successfully updated!'));
|
||||
@@ -262,7 +262,7 @@ final class PasswordController extends AbstractController
|
||||
'constraints' => [
|
||||
new Callback([
|
||||
'callback' => function ($pattern, ExecutionContextInterface $context, $payload) {
|
||||
$qb = $this->getDoctrine()->getManager()
|
||||
$qb = $this->managerRegistry->getManager()
|
||||
->createQueryBuilder();
|
||||
$qb->select('COUNT(u)')
|
||||
->from(User::class, 'u')
|
||||
|
Reference in New Issue
Block a user