mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +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:
@@ -25,7 +25,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
abstract class AbstractElementController extends AbstractController
|
||||
{
|
||||
public function __construct(protected EntityManagerInterface $em, protected TranslatorInterface $translator, protected LoggerInterface $chillMainLogger) {}
|
||||
public function __construct(protected EntityManagerInterface $em, protected TranslatorInterface $translator, protected LoggerInterface $chillMainLogger, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
|
||||
|
||||
/**
|
||||
* Route(
|
||||
@@ -60,7 +60,7 @@ abstract class AbstractElementController extends AbstractController
|
||||
'type' => $element->getType(),
|
||||
]);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->remove($element);
|
||||
$em->flush();
|
||||
|
||||
@@ -105,7 +105,7 @@ abstract class AbstractElementController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans($flashOnSuccess));
|
||||
@@ -145,7 +145,7 @@ abstract class AbstractElementController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->persist($element);
|
||||
$em->flush();
|
||||
|
||||
|
Reference in New Issue
Block a user