Skip to content

Commit 22cbf8f

Browse files
committed
minor symfony#54531 [Serializer] add $class, $format and $context arguments to NameConverterInterface methods (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [Serializer] add $class, $format and $context arguments to NameConverterInterface methods | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix symfony#53898 (comment) | License | MIT Commits ------- d088047 add $class, $format and $context arguments to NameConverterInterface methods
2 parents d600f5b + d088047 commit 22cbf8f

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
7.1
55
---
66

7+
* Add arguments `$class`, `$format` and `$context` to `NameConverterInterface::normalize()` and `NameConverterInterface::denormalize()`
78
* Add `DateTimeNormalizer::CAST_KEY` context option
89
* Add `Default` and "class name" default groups
910
* Add `AbstractNormalizer::FILTER_BOOL` context option

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author Kévin Dunglas <[email protected]>
2020
* @author Aurélien Pillevesse <[email protected]>
2121
*/
22-
class CamelCaseToSnakeCaseNameConverter implements AdvancedNameConverterInterface
22+
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
2323
{
2424
/**
2525
* Require all properties to be written in snake_case.
@@ -36,7 +36,7 @@ public function __construct(
3636
) {
3737
}
3838

39-
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
39+
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
4040
{
4141
if (null === $this->attributes || \in_array($propertyName, $this->attributes, true)) {
4242
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
@@ -45,8 +45,12 @@ public function normalize(string $propertyName, ?string $class = null, ?string $
4545
return $propertyName;
4646
}
4747

48-
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
48+
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
4949
{
50+
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
51+
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
52+
$context = 3 < \func_num_args() ? func_get_arg(3) : [];
53+
5054
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
5155
throw new UnexpectedPropertyException($propertyName);
5256
}

src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* @author Fabien Bourigault <[email protected]>
2020
*/
21-
final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
21+
final class MetadataAwareNameConverter implements NameConverterInterface
2222
{
2323
/**
2424
* @var array<string, array<string, string|null>>
@@ -41,8 +41,12 @@ public function __construct(
4141
) {
4242
}
4343

44-
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
44+
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
4545
{
46+
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
47+
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
48+
$context = 3 < \func_num_args() ? func_get_arg(3) : [];
49+
4650
if (null === $class) {
4751
return $this->normalizeFallback($propertyName, $class, $format, $context);
4852
}
@@ -54,8 +58,12 @@ public function normalize(string $propertyName, ?string $class = null, ?string $
5458
return self::$normalizeCache[$class][$propertyName] ?? $this->normalizeFallback($propertyName, $class, $format, $context);
5559
}
5660

57-
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
61+
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
5862
{
63+
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
64+
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
65+
$context = 3 < \func_num_args() ? func_get_arg(3) : [];
66+
5967
if (null === $class) {
6068
return $this->denormalizeFallback($propertyName, $class, $format, $context);
6169
}

src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ interface NameConverterInterface
2020
{
2121
/**
2222
* Converts a property name to its normalized value.
23+
*
24+
* @param class-string|null $class
25+
* @param string|null $format
26+
* @param array<string, mixed> $context
2327
*/
24-
public function normalize(string $propertyName): string;
28+
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string;
2529

2630
/**
2731
* Converts a property name to its denormalized value.
32+
*
33+
* @param class-string|null $class
34+
* @param string|null $format
35+
* @param array<string, mixed> $context
2836
*/
29-
public function denormalize(string $propertyName): string;
37+
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string;
3038
}

0 commit comments

Comments
 (0)