Skip to content

Commit 523850a

Browse files
committed
Serialization
1 parent 7d67b7d commit 523850a

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

code_samples/back_office/search/src/Search/Serializer/Normalizer/Suggestion/ProductSuggestionNormalizer.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
namespace App\Search\Serializer\Normalizer\Suggestion;
44

55
use App\Search\Model\Suggestion\ProductSuggestion;
6-
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
76
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
87
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
98
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
109

1110
class ProductSuggestionNormalizer implements
1211
NormalizerInterface,
13-
NormalizerAwareInterface,
14-
CacheableSupportsMethodInterface
12+
NormalizerAwareInterface
1513
{
1614
use NormalizerAwareTrait;
1715

18-
public function normalize($object, string $format = null, array $context = [])
16+
/**
17+
* @return array<string, string|null>
18+
*/
19+
public function normalize($object, string $format = null, array $context = []): array
1920
{
2021
/** @var \App\Search\Model\Suggestion\ProductSuggestion $object */
2122
return [
@@ -27,13 +28,15 @@ public function normalize($object, string $format = null, array $context = [])
2728
];
2829
}
2930

30-
public function supportsNormalization($data, string $format = null)
31+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
3132
{
3233
return $data instanceof ProductSuggestion;
3334
}
3435

35-
public function hasCacheableSupportsMethod(): bool
36+
public function getSupportedTypes(?string $format): array
3637
{
37-
return true;
38+
return [
39+
ProductSuggestion::class => true,
40+
];
3841
}
3942
}

code_samples/data_migration/src/Migrations/Matcher/SectionIdentifierNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function createCriterion(array $data, string $type, ?string $format, a
2525
return new Criterion\SectionIdentifier($data['value']);
2626
}
2727

28-
public function supportsNormalization($data, string $format = null): bool
28+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
2929
{
3030
return $data instanceof Criterion\SectionIdentifier;
3131
}

code_samples/field_types/2dpoint_ft/src/Serializer/Point2D/ValueDenormalizer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
final class ValueDenormalizer implements DenormalizerInterface
1010
{
11-
public function denormalize($data, string $class, string $format = null, array $context = [])
11+
public function denormalize($data, string $class, string $format = null, array $context = []): mixed
1212
{
1313
if (isset($data['x']) && isset($data['y'])) {
1414
// Support for old format
@@ -18,8 +18,15 @@ public function denormalize($data, string $class, string $format = null, array $
1818
return new $class($data);
1919
}
2020

21-
public function supportsDenormalization($data, string $type, string $format = null)
21+
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
2222
{
2323
return $type === Value::class;
2424
}
25+
26+
public function getSupportedTypes(?string $format): array
27+
{
28+
return [
29+
Value::class => true,
30+
];
31+
}
2532
}

code_samples/field_types/2dpoint_ft/src/Serializer/Point2D/ValueNormalizer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@
88

99
final class ValueNormalizer implements NormalizerInterface
1010
{
11-
public function normalize($object, string $format = null, array $context = [])
11+
/**
12+
* @return array<?float, ?float>
13+
*/
14+
public function normalize($object, string $format = null, array $context = []): array
1215
{
1316
return [
1417
$object->getX(),
1518
$object->getY(),
1619
];
1720
}
1821

19-
public function supportsNormalization($data, string $format = null)
22+
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
2023
{
2124
return $data instanceof Value;
2225
}
26+
27+
public function getSupportedTypes(?string $format): array
28+
{
29+
return [
30+
Value::class => true,
31+
];
32+
}
2333
}

0 commit comments

Comments
 (0)