mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 13:03:50 +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:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user