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

@@ -58,7 +58,8 @@ class CalendarController extends AbstractController
private readonly PersonRepository $personRepository,
private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository,
private readonly UserRepositoryInterface $userRepository,
private readonly TranslatorInterface $translator
private readonly TranslatorInterface $translator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
) {}
/**
@@ -68,7 +69,7 @@ class CalendarController extends AbstractController
*/
public function deleteAction(Request $request, Calendar $entity)
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
[$person, $accompanyingPeriod] = [$entity->getPerson(), $entity->getAccompanyingPeriod()];
@@ -124,7 +125,7 @@ class CalendarController extends AbstractController
return $this->remoteCalendarConnector->getMakeReadyResponse($request->getUri());
}
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
[$person, $accompanyingPeriod] = [$entity->getPerson(), $entity->getAccompanyingPeriod()];
@@ -293,7 +294,7 @@ class CalendarController extends AbstractController
}
$view = null;
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
[$person, $accompanyingPeriod] = $this->getEntity($request);
@@ -391,7 +392,7 @@ class CalendarController extends AbstractController
{
throw new \Exception('not implemented');
$view = null;
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
[$user, $accompanyingPeriod] = $this->getEntity($request);
@@ -531,7 +532,7 @@ class CalendarController extends AbstractController
*/
private function getEntity(Request $request): array
{
$em = $this->getDoctrine()->getManager();
$em = $this->managerRegistry->getManager();
$person = $accompanyingPeriod = null;
if ($request->query->has('person_id')) {