From f4ed7e42542494e5eaa24425ffca797d800bec6e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 28 May 2025 16:10:07 +0200 Subject: [PATCH] Correct injection of services --- .../Controller/StoredObjectApiController.php | 3 --- .../CRUD/Controller/AbstractCRUDController.php | 16 +++++++++++++++- .../CRUD/Controller/ApiController.php | 5 ----- .../Controller/AddressApiController.php | 7 ------- .../AccompanyingCourseApiController.php | 3 --- .../Controller/HouseholdApiController.php | 3 --- .../Controller/HouseholdMemberController.php | 3 --- .../Controller/PersonApiController.php | 1 - 8 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectApiController.php b/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectApiController.php index 5e9d7b910..aa1540444 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectApiController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/StoredObjectApiController.php @@ -27,10 +27,7 @@ class StoredObjectApiController extends ApiController public function __construct( private readonly Security $security, private readonly EntityManagerInterface $entityManager, - SerializerInterface $serializer, - ManagerRegistry $managerRegistry, ) { - parent::__construct($serializer, $managerRegistry); } /** diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php index 9cbb1793a..1e3a1b1a9 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php @@ -28,6 +28,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\ConflictHttpException; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Symfony\Contracts\Service\Attribute\Required; use Symfony\Contracts\Translation\TranslatorInterface; abstract class AbstractCRUDController extends AbstractController @@ -39,10 +40,23 @@ abstract class AbstractCRUDController extends AbstractController */ protected array $crudConfig = []; - public function __construct(protected readonly SerializerInterface $serializer, protected readonly ManagerRegistry $managerRegistry) + protected ManagerRegistry $managerRegistry; + protected SerializerInterface $serializer; + + #[Required] + public function setSerializer(SerializerInterface $serializer): void { + $this->serializer = $serializer; } + #[Required] + public function setManagerRegistry(ManagerRegistry $managerRegistry): void + { + $this->managerRegistry = $managerRegistry; + } + +// public function __construct(protected readonly SerializerInterface $serializer, protected readonly ManagerRegistry $managerRegistry) {} + /** * get the role given from the config. */ diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index 1137754a3..dcfe1aa0b 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -24,11 +24,6 @@ use Symfony\Component\Validator\ConstraintViolationListInterface; class ApiController extends AbstractCRUDController { - public function __construct(SerializerInterface $serializer, ManagerRegistry $managerRegistry) - { - parent::__construct($serializer, $managerRegistry); - } - /** * Base method for handling api action. * diff --git a/src/Bundle/ChillMainBundle/Controller/AddressApiController.php b/src/Bundle/ChillMainBundle/Controller/AddressApiController.php index c359bbb5e..19660f66c 100644 --- a/src/Bundle/ChillMainBundle/Controller/AddressApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/AddressApiController.php @@ -23,13 +23,6 @@ use Symfony\Component\Serializer\SerializerInterface; class AddressApiController extends ApiController { - public function __construct( - SerializerInterface $serializer, - ManagerRegistry $managerRegistry, - ) { - parent::__construct($serializer, $managerRegistry); - } - /** * Duplicate an existing address. */ diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index a89b5e0fb..f575580b7 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -55,10 +55,7 @@ final class AccompanyingCourseApiController extends ApiController private readonly Registry $registry, private readonly ValidatorInterface $validator, private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, - ManagerRegistry $managerRegistry, - SerializerInterface $serializer, ) { - parent::__construct($serializer, $managerRegistry); } public function commentApi($id, Request $request, string $_format): Response diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php index fc460aad3..872dc0e5c 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php @@ -37,10 +37,7 @@ class HouseholdApiController extends ApiController private readonly EventDispatcherInterface $eventDispatcher, private readonly HouseholdRepository $householdRepository, private readonly HouseholdACLAwareRepositoryInterface $householdACLAwareRepository, - ManagerRegistry $managerRegistry, - SerializerInterface $serializer, ) { - parent::__construct($serializer, $managerRegistry); } /** diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index a27c9cf7e..e6d1ccb76 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -47,11 +47,8 @@ class HouseholdMemberController extends ApiController private readonly HouseholdRepository $householdRepository, private readonly Security $security, private readonly PositionRepository $positionRepository, - ManagerRegistry $managerRegistry, - SerializerInterface $serializer, protected ParameterBagInterface $parameterBag, ) { - parent::__construct($serializer, $managerRegistry); $this->household_fields_visibility = $parameterBag->get('chill_person.household_fields'); } diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php index 917104f4e..b8120d5c5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php @@ -22,7 +22,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; class PersonApiController extends ApiController {