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

@@ -77,7 +77,8 @@ class EventController extends AbstractController
AuthorizationHelper $authorizationHelper,
FormFactoryInterface $formFactoryInterface,
TranslatorInterface $translator,
PaginatorFactory $paginator
PaginatorFactory $paginator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
) {
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
@@ -91,7 +92,7 @@ class EventController extends AbstractController
*/
public function deleteAction($event_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$event = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->findOneBy([
'id' => $event_id,
]);
@@ -144,7 +145,7 @@ class EventController extends AbstractController
*/
public function editAction($event_id)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->find($event_id);
@@ -171,7 +172,7 @@ class EventController extends AbstractController
*/
public function listByPersonAction($person_id)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id);
@@ -235,7 +236,7 @@ class EventController extends AbstractController
{
if (null === $center) {
$center_id = $request->query->get('center_id');
$center = $this->getDoctrine()->getRepository(Center::class)->find($center_id);
$center = $this->managerRegistry->getRepository(Center::class)->find($center_id);
}
$entity = new Event();
@@ -245,7 +246,7 @@ class EventController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$em->persist($entity);
$em->flush();
@@ -350,7 +351,7 @@ class EventController extends AbstractController
*/
public function updateAction(Request $request, $event_id): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->find($event_id);