mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33: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:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user