Inject managerRegistry and serializerInterface directly into controllers

This commit is contained in:
2025-05-28 12:04:27 +02:00
parent cc20e8896f
commit abfdf2ec6d
7 changed files with 70 additions and 25 deletions

View File

@@ -30,6 +30,7 @@ use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -39,6 +40,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -46,7 +48,18 @@ use Symfony\Component\Workflow\Registry;
final class AccompanyingCourseApiController extends ApiController
{
public function __construct(private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ReferralsSuggestionInterface $referralAvailable, private readonly Registry $registry, private readonly ValidatorInterface $validator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository) {}
public function __construct(
private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ReferralsSuggestionInterface $referralAvailable,
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
{

View File

@@ -22,16 +22,26 @@ use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use Chill\PersonBundle\Repository\Household\HouseholdACLAwareRepositoryInterface;
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Doctrine\Persistence\ManagerRegistry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class HouseholdApiController extends ApiController
{
public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly HouseholdRepository $householdRepository, private readonly HouseholdACLAwareRepositoryInterface $householdACLAwareRepository, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly HouseholdRepository $householdRepository,
private readonly HouseholdACLAwareRepositoryInterface $householdACLAwareRepository,
ManagerRegistry $managerRegistry,
SerializerInterface $serializer,
) {
parent::__construct($serializer, $managerRegistry);
}
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse

View File

@@ -12,9 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Form\HouseholdMemberType;
use Chill\PersonBundle\Household\MembersEditor;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
@@ -23,6 +21,7 @@ use Chill\PersonBundle\Repository\Household\PositionRepository;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -32,6 +31,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Serializer\Exception;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -47,9 +47,11 @@ class HouseholdMemberController extends ApiController
private readonly HouseholdRepository $householdRepository,
private readonly Security $security,
private readonly PositionRepository $positionRepository,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
ManagerRegistry $managerRegistry,
SerializerInterface $serializer,
protected ParameterBagInterface $parameterBag,
) {
parent::__construct($serializer, $managerRegistry);
$this->household_fields_visibility = $parameterBag->get('chill_person.household_fields');
}
@@ -143,10 +145,10 @@ class HouseholdMemberController extends ApiController
$data = [
'persons' => $persons ?? false ?
$this->getSerializer()->normalize($persons, 'json', ['groups' => ['read']]) : [],
$this->serializer->normalize($persons, 'json', ['groups' => ['read']]) : [],
'household' => $household ?? false ?
$this->getSerializer()->normalize($household, 'json', ['groups' => ['read']]) : null,
'positions' => $this->getSerializer()->normalize($positions, 'json', ['groups' => ['read']]),
$this->serializer->normalize($household, 'json', ['groups' => ['read']]) : null,
'positions' => $this->serializer->normalize($positions, 'json', ['groups' => ['read']]),
'allowHouseholdCreate' => $allowHouseholdCreate ?? true,
'allowHouseholdSearch' => $allowHouseholdSearch ?? true,
'allowLeaveWithoutHousehold' => $allowLeaveWithoutHousehold ?? $request->query->has('allow_leave_without_household'),
@@ -176,7 +178,7 @@ class HouseholdMemberController extends ApiController
{
try {
/** @var MembersEditor $editor */
$editor = $this->getSerializer()
$editor = $this->serializer
->deserialize(
$request->getContent(),
MembersEditor::class,