src/Contact/Serializer/Normalizer/Relationship/EmploymentNormalizer.php line 53
<?phpdeclare(strict_types=1);/*** Copyright (c) 2021 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2021 TECLA Consulting Group oü*/namespace App\Contact\Serializer\Normalizer\Relationship;use App\Contact\Model\Relationship\EmploymentInterface;use App\Contact\Security\Relationship\Employment\CanDeleteEmployeePermission;use App\Contact\Security\Relationship\Employment\CanDeleteEmployerPermission;use App\Contact\Security\Relationship\Employment\CanUpdateEmployeePermission;use App\Contact\Security\Relationship\Employment\CanUpdateEmployerPermission;use App\Core\Serializer\Normalizer\AttributeAwareNormalizerTrait;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;use Symfony\Component\Serializer\Normalizer\NormalizerInterface;final class EmploymentNormalizer implements ContextAwareNormalizerInterface, CacheableSupportsMethodInterface{use AttributeAwareNormalizerTrait;private NormalizerInterface $normalizer;private UrlGeneratorInterface $urlGenerator;private AuthorizationCheckerInterface $authorizationChecker;public function __construct(NormalizerInterface $normalizer,UrlGeneratorInterface $urlGenerator,AuthorizationCheckerInterface $authorizationChecker) {$this->normalizer = $normalizer;$this->urlGenerator = $urlGenerator;$this->authorizationChecker = $authorizationChecker;}public function normalize($object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null{$data = $this->normalizer->normalize($object, $format, $context);if (true === $this->shouldSerializeAttribute($data, EmploymentInterface::ATTR__LINKS, $context)) {$this->normalize_Links($object, $data);}return $data;}public function supportsNormalization($data, string $format = null, array $context = []): bool{return $data instanceof EmploymentInterface;}public function hasCacheableSupportsMethod(): bool{return __CLASS__ === static::class;}private function normalize_Links(EmploymentInterface $relationship, array &$data): void{$ajaxLinks = [];if (true === $this->authorizationChecker->isGranted(CanUpdateEmployeePermission::class, $relationship)) {$ajaxLinks['edit'] = $this->urlGenerator->generate('app.contact.ajax.contact_relationship.employment.employee.edit', ['contactId' => $relationship->getEmployer()->getId(),'relationshipId' => $relationship->getId(),]);}if (true === $this->authorizationChecker->isGranted(CanUpdateEmployerPermission::class, $relationship)) {$ajaxLinks['editEmployer'] = $this->urlGenerator->generate('app.contact.ajax.contact_relationship.employment.employer.edit', ['contactId' => $relationship->getEmployee()->getId(),'relationshipId' => $relationship->getId(),]);}if (true === $this->authorizationChecker->isGranted(CanDeleteEmployeePermission::class, $relationship)) {$ajaxLinks['remove'] = $this->urlGenerator->generate('app.contact.ajax.contact_relationship.employment.employee.remove', ['contactId' => $relationship->getEmployer()->getId(),'relationshipId' => $relationship->getId(),]);}if (true === $this->authorizationChecker->isGranted(CanDeleteEmployerPermission::class, $relationship)) {$ajaxLinks['removeEmployer'] = $this->urlGenerator->generate('app.contact.ajax.contact_relationship.employment.employer.remove', ['contactId' => $relationship->getEmployee()->getId(),'relationshipId' => $relationship->getId(),]);}$data[EmploymentInterface::ATTR__LINKS] = ['ajax' => $ajaxLinks,];}}