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

@@ -29,14 +29,14 @@ class PersonAddressController extends AbstractController
/**
* PersonAddressController constructor.
*/
public function __construct(private readonly ValidatorInterface $validator, private readonly TranslatorInterface $translator) {}
public function __construct(private readonly ValidatorInterface $validator, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
/**
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/address/create", name="chill_person_address_create", methods={"POST"})
*/
public function createAction(mixed $person_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
$person = $this->managerRegistry->getManager()
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
@@ -65,7 +65,7 @@ class PersonAddressController extends AbstractController
$this->addFlash('error', $error->getMessage());
}
} elseif ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$em->flush();
$this->addFlash(
@@ -93,7 +93,7 @@ class PersonAddressController extends AbstractController
*/
public function editAction(mixed $person_id, mixed $address_id)
{
$person = $this->getDoctrine()->getManager()
$person = $this->managerRegistry->getManager()
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
@@ -123,7 +123,7 @@ class PersonAddressController extends AbstractController
*/
public function listAction(mixed $person_id)
{
$person = $this->getDoctrine()->getManager()
$person = $this->managerRegistry->getManager()
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
@@ -147,7 +147,7 @@ class PersonAddressController extends AbstractController
*/
public function newAction(mixed $person_id)
{
$person = $this->getDoctrine()->getManager()
$person = $this->managerRegistry->getManager()
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
@@ -176,7 +176,7 @@ class PersonAddressController extends AbstractController
*/
public function updateAction(mixed $person_id, mixed $address_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
$person = $this->managerRegistry->getManager()
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
@@ -203,7 +203,7 @@ class PersonAddressController extends AbstractController
$this->addFlash('error', $error->getMessage());
}
} elseif ($form->isValid()) {
$this->getDoctrine()->getManager()
$this->managerRegistry->getManager()
->flush();
$this->addFlash('success', $this->translator->trans(
@@ -276,7 +276,7 @@ class PersonAddressController extends AbstractController
*/
protected function findAddressById(Person $person, $address_id)
{
$address = $this->getDoctrine()->getManager()
$address = $this->managerRegistry->getManager()
->getRepository(Address::class)
->find($address_id);