Skip to content

Commit db2cc95

Browse files
authored
feat(serializer): support for getSupportedTypes (symfony 6.3) (#5672)
1 parent 26bf8ae commit db2cc95

File tree

53 files changed

+363
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+363
-0
lines changed

src/Elasticsearch/Serializer/ItemNormalizer.php

+13
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ public function supportsNormalization(mixed $data, string $format = null, array
9090
return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsNormalization($data, $format);
9191
}
9292

93+
public function getSupportedTypes($format): array
94+
{
95+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
96+
if (!method_exists($this->decorated, 'getSupportedTypes')) {
97+
return [
98+
DocumentNormalizer::FORMAT => null,
99+
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
100+
];
101+
}
102+
103+
return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
104+
}
105+
93106
/**
94107
* {@inheritdoc}
95108
*

src/GraphQl/Serializer/Exception/ErrorNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
3939
{
4040
return $data instanceof Error;
4141
}
42+
43+
public function getSupportedTypes($format): array
44+
{
45+
return [
46+
Error::class => true,
47+
];
48+
}
4249
}

src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
5050
{
5151
return $data instanceof Error && $data->getPrevious() instanceof HttpExceptionInterface;
5252
}
53+
54+
public function getSupportedTypes($format): array
55+
{
56+
return [
57+
Error::class => false,
58+
];
59+
}
5360
}

src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
4444
{
4545
return $data instanceof Error && $data->getPrevious() instanceof \RuntimeException;
4646
}
47+
48+
public function getSupportedTypes($format): array
49+
{
50+
return [
51+
Error::class => false,
52+
];
53+
}
4754
}

src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
7777
{
7878
return $data instanceof Error && $data->getPrevious() instanceof ValidationException;
7979
}
80+
81+
public function getSupportedTypes($format): array
82+
{
83+
return [
84+
Error::class => false,
85+
];
86+
}
8087
}

src/GraphQl/Serializer/ItemNormalizer.php

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
5656
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
5757
}
5858

59+
public function getSupportedTypes($format): array
60+
{
61+
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
62+
}
63+
5964
/**
6065
* {@inheritdoc}
6166
*

src/GraphQl/Serializer/ObjectNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,25 @@ public function supportsNormalization(mixed $data, string $format = null, array
4444
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
4545
}
4646

47+
public function getSupportedTypes($format): array
48+
{
49+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
50+
if (!method_exists($this->decorated, 'getSupportedTypes')) {
51+
return [
52+
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
53+
];
54+
}
55+
56+
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
57+
}
58+
4759
/**
4860
* {@inheritdoc}
4961
*/
5062
public function hasCacheableSupportsMethod(): bool
5163
{
64+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
65+
5266
return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
5367
}
5468

src/Hal/Serializer/EntrypointNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
7474
return self::FORMAT === $format && $data instanceof Entrypoint;
7575
}
7676

77+
public function getSupportedTypes($format): array
78+
{
79+
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
80+
}
81+
7782
public function hasCacheableSupportsMethod(): bool
7883
{
84+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
85+
7986
return true;
8087
}
8188
}

src/Hal/Serializer/ItemNormalizer.php

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
4646
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
4747
}
4848

49+
public function getSupportedTypes($format): array
50+
{
51+
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
52+
}
53+
4954
/**
5055
* {@inheritdoc}
5156
*/

src/Hal/Serializer/ObjectNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,25 @@ public function supportsNormalization(mixed $data, string $format = null, array
3939
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
4040
}
4141

42+
public function getSupportedTypes($format): array
43+
{
44+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
45+
if (!method_exists($this->decorated, 'getSupportedTypes')) {
46+
return [
47+
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
48+
];
49+
}
50+
51+
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
52+
}
53+
4254
/**
4355
* {@inheritdoc}
4456
*/
4557
public function hasCacheableSupportsMethod(): bool
4658
{
59+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
60+
4761
return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
4862
}
4963

src/Hydra/Serializer/CollectionFiltersNormalizer.php

+12
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,20 @@ public function supportsNormalization(mixed $data, string $format = null, array
5050
return $this->collectionNormalizer->supportsNormalization($data, $format, $context);
5151
}
5252

53+
public function getSupportedTypes($format): array
54+
{
55+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
56+
if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) {
57+
return ['*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod()];
58+
}
59+
60+
return $this->collectionNormalizer->getSupportedTypes($format);
61+
}
62+
5363
public function hasCacheableSupportsMethod(): bool
5464
{
65+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
66+
5567
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
5668
}
5769

src/Hydra/Serializer/DocumentationNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
544544
return self::FORMAT === $format && $data instanceof Documentation;
545545
}
546546

547+
public function getSupportedTypes($format): array
548+
{
549+
return self::FORMAT === $format ? [Documentation::class => true] : [];
550+
}
551+
547552
public function hasCacheableSupportsMethod(): bool
548553
{
554+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
555+
549556
return true;
550557
}
551558
}

src/Hydra/Serializer/EntrypointNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
8383
return self::FORMAT === $format && $data instanceof Entrypoint;
8484
}
8585

86+
public function getSupportedTypes($format): array
87+
{
88+
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
89+
}
90+
8691
public function hasCacheableSupportsMethod(): bool
8792
{
93+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
94+
8895
return true;
8996
}
9097
}

src/Hydra/Serializer/ErrorNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
6565
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
6666
}
6767

68+
public function getSupportedTypes($format): array
69+
{
70+
if (self::FORMAT === $format) {
71+
return [
72+
\Exception::class => true,
73+
FlattenException::class => true,
74+
];
75+
}
76+
77+
return [];
78+
}
79+
6880
public function hasCacheableSupportsMethod(): bool
6981
{
82+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
83+
7084
return true;
7185
}
7286
}

src/Hydra/Serializer/PartialCollectionViewNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
106106
return $this->collectionNormalizer->supportsNormalization($data, $format, $context);
107107
}
108108

109+
public function getSupportedTypes($format): array
110+
{
111+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
112+
if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) {
113+
return [
114+
'*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(),
115+
];
116+
}
117+
118+
return $this->collectionNormalizer->getSupportedTypes($format);
119+
}
120+
109121
public function hasCacheableSupportsMethod(): bool
110122
{
123+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
124+
111125
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
112126
}
113127

src/JsonApi/Serializer/ConstraintViolationListNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
5959
return self::FORMAT === $format && $data instanceof ConstraintViolationListInterface;
6060
}
6161

62+
public function getSupportedTypes($format): array
63+
{
64+
return (self::FORMAT === $format) ? [ConstraintViolationListInterface::class => true] : [];
65+
}
66+
6267
public function hasCacheableSupportsMethod(): bool
6368
{
69+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
70+
6471
return true;
6572
}
6673

src/JsonApi/Serializer/EntrypointNormalizer.php

+7
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
7474
return self::FORMAT === $format && $data instanceof Entrypoint;
7575
}
7676

77+
public function getSupportedTypes($format): array
78+
{
79+
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
80+
}
81+
7782
public function hasCacheableSupportsMethod(): bool
7883
{
84+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
85+
7986
return true;
8087
}
8188
}

src/JsonApi/Serializer/ErrorNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
6767
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
6868
}
6969

70+
public function getSupportedTypes($format): array
71+
{
72+
if (self::FORMAT === $format) {
73+
return [
74+
\Exception::class => true,
75+
FlattenException::class => true,
76+
];
77+
}
78+
79+
return [];
80+
}
81+
7082
public function hasCacheableSupportsMethod(): bool
7183
{
84+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
85+
7286
return true;
7387
}
7488
}

src/JsonApi/Serializer/ItemNormalizer.php

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
6565
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
6666
}
6767

68+
public function getSupportedTypes($format): array
69+
{
70+
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
71+
}
72+
6873
/**
6974
* {@inheritdoc}
7075
*/

src/JsonApi/Serializer/ObjectNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
4242
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
4343
}
4444

45+
public function getSupportedTypes($format): array
46+
{
47+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
48+
if (!method_exists($this->decorated, 'getSupportedTypes')) {
49+
return [
50+
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
51+
];
52+
}
53+
54+
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
55+
}
56+
4557
public function hasCacheableSupportsMethod(): bool
4658
{
59+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
60+
4761
return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
4862
}
4963

src/JsonLd/Serializer/ItemNormalizer.php

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
5858
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
5959
}
6060

61+
public function getSupportedTypes($format): array
62+
{
63+
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
64+
}
65+
6166
/**
6267
* {@inheritdoc}
6368
*

src/JsonLd/Serializer/ObjectNormalizer.php

+14
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
4141
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
4242
}
4343

44+
public function getSupportedTypes($format): array
45+
{
46+
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
47+
if (!method_exists($this->decorated, 'getSupportedTypes')) {
48+
return [
49+
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
50+
];
51+
}
52+
53+
return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
54+
}
55+
4456
public function hasCacheableSupportsMethod(): bool
4557
{
58+
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
59+
4660
return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
4761
}
4862

0 commit comments

Comments
 (0)