mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 23:04:58 +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:
@@ -23,6 +23,9 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*/
|
||||
class EntityPersonCRUDController extends CRUDController
|
||||
{
|
||||
public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Override the base method to add a filtering step to a person.
|
||||
*
|
||||
@@ -102,7 +105,7 @@ class EntityPersonCRUDController extends CRUDController
|
||||
return null;
|
||||
}
|
||||
|
||||
$person = $this->getDoctrine()
|
||||
$person = $this->managerRegistry
|
||||
->getRepository(Person::class)
|
||||
->find($request->query->getInt('person_id'));
|
||||
|
||||
|
@@ -20,6 +20,9 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class OneToOneEntityPersonCRUDController extends CRUDController
|
||||
{
|
||||
public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry)
|
||||
{
|
||||
}
|
||||
protected function generateRedirectOnCreateRoute($action, Request $request, $entity): string
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented yet.');
|
||||
@@ -31,7 +34,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController
|
||||
|
||||
if (null === $entity) {
|
||||
$entity = $this->createEntity($action, $request);
|
||||
$person = $this->getDoctrine()
|
||||
$person = $this->managerRegistry
|
||||
->getManager()
|
||||
->getRepository(Person::class)
|
||||
->find($id);
|
||||
@@ -58,7 +61,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController
|
||||
|
||||
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
|
||||
{
|
||||
if (false === $this->getDoctrine()->getManager()->contains($entity)) {
|
||||
if (false === $this->managerRegistry->getManager()->contains($entity)) {
|
||||
return new RedirectResponse($this->generateRedirectOnCreateRoute($action, $request, $entity));
|
||||
}
|
||||
|
||||
@@ -67,6 +70,6 @@ class OneToOneEntityPersonCRUDController extends CRUDController
|
||||
|
||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
$this->getDoctrine()->getManager()->persist($entity);
|
||||
$this->managerRegistry->getManager()->persist($entity);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user