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:
2023-12-16 19:09:34 +01:00
parent 655dc02538
commit 5703fd0046
54 changed files with 281 additions and 228 deletions

View File

@@ -36,7 +36,8 @@ class DocumentAccompanyingCourseController extends AbstractController
public function __construct(
protected TranslatorInterface $translator,
protected EventDispatcherInterface $eventDispatcher,
protected AuthorizationHelper $authorizationHelper
protected AuthorizationHelper $authorizationHelper,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
) {}
/**
@@ -52,8 +53,8 @@ class DocumentAccompanyingCourseController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->remove($document);
$this->getDoctrine()->getManager()->flush();
$this->managerRegistry->getManager()->remove($document);
$this->managerRegistry->getManager()->flush();
$this->addFlash('success', $this->translator->trans('The document is successfully removed'));
@@ -91,7 +92,7 @@ class DocumentAccompanyingCourseController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->managerRegistry->getManager()->flush();
$this->addFlash('success', $this->translator->trans('The document is successfully updated'));
@@ -141,7 +142,7 @@ class DocumentAccompanyingCourseController extends AbstractController
'creation of this activity not allowed'
);
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$em->persist($document);
$em->flush();