-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Re-add AdvancedNameConverterInterface
#58307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* @author Kévin Dunglas <[email protected]> | ||
* @author Aurélien Pillevesse <[email protected]> | ||
*/ | ||
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface | ||
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface, AdvancedNameConverterInterface | ||
{ | ||
/** | ||
* Require all properties to be written in snake_case. | ||
|
@@ -41,7 +41,7 @@ | |
* @param string|null $format | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string | ||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string | ||
Check failure on line 44 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php
|
||
{ | ||
if (null === $this->attributes || \in_array($propertyName, $this->attributes, true)) { | ||
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName))); | ||
|
@@ -55,12 +55,8 @@ | |
* @param string|null $format | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string | ||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string | ||
Check failure on line 58 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php
|
||
{ | ||
$class = 1 < \func_num_args() ? func_get_arg(1) : null; | ||
$format = 2 < \func_num_args() ? func_get_arg(2) : null; | ||
$context = 3 < \func_num_args() ? func_get_arg(3) : []; | ||
|
||
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) { | ||
throw new UnexpectedPropertyException($propertyName); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
/** | ||
* @author Fabien Bourigault <[email protected]> | ||
*/ | ||
final class MetadataAwareNameConverter implements NameConverterInterface | ||
final class MetadataAwareNameConverter implements NameConverterInterface, AdvancedNameConverterInterface | ||
{ | ||
/** | ||
* @var array<string, array<string, string|null>> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CamelCaseToSnakeCaseNameConverter was not an advanced converter in 7.0 so there is nothing to re-add there, and adding the arguments in the signature natively is a BC break for child classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, you're right, plus I didn't get all the history of that PR (#53898 (comment)).
I'm going to close that PR, thanks!