8000 [Serializer] Add class/format/context to NameConverterInterface · symfony/symfony-docs@b53029a · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit b53029a

Browse files
mttschwouterj
authored andcommitted
[Serializer] Add class/format/context to NameConverterInterface
Fix #19683
1 parent 79f9407 commit b53029a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

serializer/custom_name_converter.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,26 @@ A custom name converter can handle such cases::
3030

3131
class OrgPrefixNameConverter implements NameConverterInterface
3232
{
33-
public function normalize(string $propertyName): string
33+
public function normalize(string $propertyName, string $class = null, ?string $format = null, array $context = []): string
3434
{
3535
// during normalization, add the prefix
3636
return 'org_'.$propertyName;
3737
}
3838

39-
public function denormalize(string $propertyName): string
39+
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
4040
{
4141
// remove the 'org_' prefix on denormalizing
4242
return str_starts_with($propertyName, 'org_') ? substr($propertyName, 4) : $propertyName;
4343
}
4444
}
4545

46+
.. versionadded:: 7.1
47+
48+
Accessing the current class name, format and context via
49+
:method:`Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize`
50+
and :method:`Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::denormalize`
51+
was introduced in Symfony 7.1.
52+
4653
.. note::
4754

4855
You can also implement

0 commit comments

Comments
 (0)
0