src/Contact/Serializer/Normalizer/Relationship/OwnershipNormalizer.php line 41
<?phpdeclare(strict_types=1);/*** Copyright (c) 2023 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 2023 TECLA Consulting Group oü*/namespace App\Contact\Serializer\Normalizer\Relationship;use App\Contact\Model\Relationship\OwnershipInterface;use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;use Symfony\Component\Serializer\Normalizer\NormalizerInterface;use Twig\Environment;final class OwnershipNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface{private NormalizerInterface $normalizer;private Environment $twig;public function __construct(NormalizerInterface $normalizer,Environment $twig) {$this->normalizer = $normalizer;$this->twig = $twig;}public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null{$data = $this->normalizer->normalize($object, $format, $context);$this->normalizeHtml($object, $context, $data);return $data;}public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool{return $data instanceof OwnershipInterface;}public function hasCacheableSupportsMethod(): bool{return __CLASS__ === self::class;}private function getGroups(array $context): array{$groups = $context[AbstractNormalizer::GROUPS] ?? [];return \is_scalar($groups) ? (array) $groups : $groups;}private function normalizeHtml(OwnershipInterface $ownership, array $context, array &$data): void{$groups = $this->getGroups($context);if (!\in_array('ownership.owner.list', $groups) && !\in_array('ownership.company.list', $groups)) {return;}if (\in_array('ownership.owner.list', $groups)) {$html = $this->twig->load('packages/contact/fragment/relationship/ownership/_owner_list_row.html.twig');} else {$html = $this->twig->load('packages/contact/fragment/relationship/ownership/_company_list_row.html.twig');}$data['_html'] = $html->render(['ownership' => $ownership]);}}