* @ParamConverter("importLegalEntity", converter="import_legal_entity")
* @Security("user.getId() === legalEntity.getOwnerIdValue()")
Зарегистрировал в services_param_converter.yaml:
App\Infrastructure\Service\ParamConverter\ImportLegalEntityParamConverter:
arguments:
- '@infra.repo.import_legal_entity'
tags:
- { name: request.param_converter, converter: import_legal_entity }
Также services.yaml:
infra.repo.import_legal_entity:
alias: 'App\Infrastructure\Repository\LegalEntityRepository'
public: true
И сам
ImportLegalEntityParamConverter.php
<?php
namespace App\Infrastructure\Service\ParamConverter;
use App\Domain\Entity\LegalEntity;
use App\Domain\Repository\LegalEntityRepositoryInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class ImportLegalEntityParamConverter implements ParamConverterInterface
{
/**
* @var LegalEntityRepositoryInterface
*/
private $legalEntityRepository;
/**
* LegalEntityParamConverter constructor.
*
* @param LegalEntityRepositoryInterface $legalEntityRepository
*/
public function __construct(LegalEntityRepositoryInterface $legalEntityRepository)
{
$this->legalEntityRepository = $legalEntityRepository;
}
/**
* @param Request $request
* @param ParamConverter $configuration
*
* @return bool|void
*
* @throws NotFoundHttpException
*/
public function apply(Request $request, ParamConverter $configuration): bool
{
$legalEntity = null;
$legalEntityId = null;
if ($request->attributes->has('id')) {
$legalEntityId = (int) $request->attributes->get('id');
} elseif ($request->attributes->has('legalEntityId')) {
$legalEntityId = (int) $request->attributes->get('legalEntityId');
} elseif ($request->request->has('legalEntityId')) {
$legalEntityId = (int) $request->request->get('legalEntityId');
} elseif ($request->query->has('legalEntityId')) {
$legalEntityId = (int) $request->query->get('legalEntityId');
}
if (null !== $legalEntityId) {
$legalEntity = $this->legalEntityRepository->findById($legalEntityId);
if (null === $legalEntity) {
throw new NotFoundHttpException('generic.exception.legal_entity.not_exists');
}
}
$request->attributes->set($configuration->getName(), $legalEntity);
return true;
}
/**
* @param ParamConverter $configuration
*
* @return bool
*/
public function supports(ParamConverter $configuration)
{
return LegalEntity::class === $configuration->getClass();
}
}
Часть контроллера где использую ParamConverter:
* @ParamConverter("legalEntity", converter="legal_entity")
*
* @Security("(user.getGroupId() === legalEntity.getGroupIdValue() && legalEntity.isAlterable()) || user.getId() === legalEntity.getOwnerIdValue()")
* @Security("null !== user.getPrivilege()")
*
* @param Request $request
* @param LegalEntity $legalEntity
*
* @return JsonResponse
*
* @throws BirthdayInvalidException
* @throws CivilityInvalidException
* @throws DateInvalidException
* @throws EmailInvalidException
* @throws FeelingInvalidException
* @throws GeoPointInvalidException
* @throws LanguageInvalidException
* @throws ModelException
* @throws NotValidFormException
* @throws OpportunityInvalidException
* @throws PermissionInvalidException
* @throws PhoneNumberInvalidException
* @throws RoleInvalidException
* @throws SituationInvalidException
* @throws TypeInvalidException
* @throws UserTokenInvalidException
* @throws \App\Domain\Exception\Property\MainPictureInvalidException
*/
public function importLegalEntityCreateAction(Request $request, LegalEntity $legalEntity): JsonResponse
Начинаю работать с @ParamConverter и все сделал вроде бы! правильно, но... вот такая ошибка:
{
"message": "Unable to get a property on a non-object."
}