From b53029a64602d1cde5aa704ae1145532ee875bf3 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 22 Apr 2024 18:56:41 +0200 Subject: [PATCH] [Serializer] Add class/format/context to NameConverterInterface Fix #19683 --- serializer/custom_name_converter.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/serializer/custom_name_converter.rst b/serializer/custom_name_converter.rst index 82247134217..d0ed45bdc0a 100644 --- a/serializer/custom_name_converter.rst +++ b/serializer/custom_name_converter.rst @@ -30,19 +30,26 @@ A custom name converter can handle such cases:: class OrgPrefixNameConverter implements NameConverterInterface { - public function normalize(string $propertyName): string + public function normalize(string $propertyName, string $class = null, ?string $format = null, array $context = []): string { // during normalization, add the prefix return 'org_'.$propertyName; } - public function denormalize(string $propertyName): string + public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string { // remove the 'org_' prefix on denormalizing return str_starts_with($propertyName, 'org_') ? substr($propertyName, 4) : $propertyName; } } +.. versionadded:: 7.1 + + Accessing the current class name, format and context via + :method:`Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize` + and :method:`Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::denormalize` + was introduced in Symfony 7.1. + .. note:: You can also implement