mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
fix normalization for docgen
This commit is contained in:
parent
c61577edda
commit
90bebbad7d
@ -40,6 +40,7 @@ class UserJob
|
|||||||
* @var array|string[]A
|
* @var array|string[]A
|
||||||
* @ORM\Column(name="label", type="json")
|
* @ORM\Column(name="label", type="json")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
protected array $label = [];
|
protected array $label = [];
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@ use libphonenumber\PhoneNumber;
|
|||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
|
||||||
class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterface
|
class PhonenumberNormalizer implements ContextAwareNormalizerInterface, DenormalizerInterface
|
||||||
{
|
{
|
||||||
private string $defaultCarrierCode;
|
private string $defaultCarrierCode;
|
||||||
|
|
||||||
@ -53,6 +54,10 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac
|
|||||||
|
|
||||||
public function normalize($object, ?string $format = null, array $context = []): string
|
public function normalize($object, ?string $format = null, array $context = []): string
|
||||||
{
|
{
|
||||||
|
if ($format === 'docgen' && null === $object) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return $this->phoneNumberUtil->formatOutOfCountryCallingNumber($object, $this->defaultCarrierCode);
|
return $this->phoneNumberUtil->formatOutOfCountryCallingNumber($object, $this->defaultCarrierCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +66,18 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac
|
|||||||
return 'libphonenumber\PhoneNumber' === $type;
|
return 'libphonenumber\PhoneNumber' === $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, ?string $format = null)
|
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||||
{
|
{
|
||||||
return $data instanceof PhoneNumber;
|
if ($data instanceof PhoneNumber && $format === 'json') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($format === 'docgen' && (
|
||||||
|
$data instanceof PhoneNumber || PhoneNumber::class === ($context['docgen:expects'] ?? null)
|
||||||
|
)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user