Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions serializer/custom_name_converter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,26 @@

class OrgPrefixNameConverter implements NameConverterInterface
{
public function normalize(string $propertyName): string
public function normalize(string $propertyName, string $class = null, ?string $format = null, array $context = []): string

Check failure on line 33 in serializer/custom_name_converter.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please use explicit nullable types.
{
// 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
Expand Down
Loading