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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

0 commit comments

Comments
 (0)