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

@@ -22,6 +22,9 @@ use Symfony\Component\HttpFoundation\Request;
*/
class StatusController extends AbstractController
{
public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry)
{
}
/**
* Creates a new Status entity.
*
@@ -34,7 +37,7 @@ class StatusController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$em->persist($entity);
$em->flush();
@@ -58,7 +61,7 @@ class StatusController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id);
if (!$entity) {
@@ -79,7 +82,7 @@ class StatusController extends AbstractController
*/
public function editAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id);
@@ -104,7 +107,7 @@ class StatusController extends AbstractController
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entities = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->findAll();
@@ -136,7 +139,7 @@ class StatusController extends AbstractController
*/
public function showAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id);
@@ -159,7 +162,7 @@ class StatusController extends AbstractController
*/
public function updateAction(Request $request, mixed $id)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id);