Files
chill-bundles/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodOriginNormalizer.php

52 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal we keep this normalizer, because the property 'text' may be replace by a rendering in the future
*/
final class AccompanyingPeriodOriginNormalizer implements NormalizerInterface
{
/**
* @param Origin $origin
* @param string|null $format
*/
public function normalize($origin, $format = null, array $context = []): string|int|float|bool|\ArrayObject|array|null
{
return [
'type' => 'origin',
'id' => $origin->getId(),
'label' => $origin->getLabel(),
'text' => $origin->getLabel(),
];
}
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $data instanceof Origin && 'json' === $format;
}
public function getSupportedTypes(?string $format): array
{
if ('json' !== $format) {
return [];
}
return [
Origin::class => true,
];
}
}