Skip to content

Commit

Permalink
feat(serializer): support for getSupportedTypes (symfony 6.3) (#5672)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrossard committed Jul 24, 2023
1 parent 26bf8ae commit db2cc95
Show file tree
Hide file tree
Showing 53 changed files with 363 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Elasticsearch/Serializer/ItemNormalizer.php
Expand Up @@ -90,6 +90,19 @@ public function supportsNormalization(mixed $data, string $format = null, array
return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsNormalization($data, $format);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->decorated, 'getSupportedTypes')) {
return [
DocumentNormalizer::FORMAT => null,
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
];
}

return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*
Expand Down
7 changes: 7 additions & 0 deletions src/GraphQl/Serializer/Exception/ErrorNormalizer.php
Expand Up @@ -39,4 +39,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof Error;
}

public function getSupportedTypes($format): array
{
return [
Error::class => true,
];
}
}
7 changes: 7 additions & 0 deletions src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php
Expand Up @@ -50,4 +50,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof Error && $data->getPrevious() instanceof HttpExceptionInterface;
}

public function getSupportedTypes($format): array
{
return [
Error::class => false,
];
}
}
Expand Up @@ -44,4 +44,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof Error && $data->getPrevious() instanceof \RuntimeException;
}

public function getSupportedTypes($format): array
{
return [
Error::class => false,
];
}
}
Expand Up @@ -77,4 +77,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
{
return $data instanceof Error && $data->getPrevious() instanceof ValidationException;
}

public function getSupportedTypes($format): array
{
return [
Error::class => false,
];
}
}
5 changes: 5 additions & 0 deletions src/GraphQl/Serializer/ItemNormalizer.php
Expand Up @@ -56,6 +56,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQl/Serializer/ObjectNormalizer.php
Expand Up @@ -44,11 +44,25 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->decorated, 'getSupportedTypes')) {
return [
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
];
}

return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
}

Expand Down
7 changes: 7 additions & 0 deletions src/Hal/Serializer/EntrypointNormalizer.php
Expand Up @@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $data instanceof Entrypoint;
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
5 changes: 5 additions & 0 deletions src/Hal/Serializer/ItemNormalizer.php
Expand Up @@ -46,6 +46,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Hal/Serializer/ObjectNormalizer.php
Expand Up @@ -39,11 +39,25 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->decorated, 'getSupportedTypes')) {
return [
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
];
}

return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
}

Expand Down
12 changes: 12 additions & 0 deletions src/Hydra/Serializer/CollectionFiltersNormalizer.php
Expand Up @@ -50,8 +50,20 @@ public function supportsNormalization(mixed $data, string $format = null, array
return $this->collectionNormalizer->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) {
return ['*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod()];
}

return $this->collectionNormalizer->getSupportedTypes($format);
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
}

Expand Down
7 changes: 7 additions & 0 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Expand Up @@ -544,8 +544,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $data instanceof Documentation;
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? [Documentation::class => true] : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
7 changes: 7 additions & 0 deletions src/Hydra/Serializer/EntrypointNormalizer.php
Expand Up @@ -83,8 +83,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $data instanceof Entrypoint;
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
14 changes: 14 additions & 0 deletions src/Hydra/Serializer/ErrorNormalizer.php
Expand Up @@ -65,8 +65,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
}

public function getSupportedTypes($format): array
{
if (self::FORMAT === $format) {
return [
\Exception::class => true,
FlattenException::class => true,
];
}

return [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
14 changes: 14 additions & 0 deletions src/Hydra/Serializer/PartialCollectionViewNormalizer.php
Expand Up @@ -106,8 +106,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
return $this->collectionNormalizer->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) {
return [
'*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(),
];
}

return $this->collectionNormalizer->getSupportedTypes($format);
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
}

Expand Down
7 changes: 7 additions & 0 deletions src/JsonApi/Serializer/ConstraintViolationListNormalizer.php
Expand Up @@ -59,8 +59,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $data instanceof ConstraintViolationListInterface;
}

public function getSupportedTypes($format): array
{
return (self::FORMAT === $format) ? [ConstraintViolationListInterface::class => true] : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}

Expand Down
7 changes: 7 additions & 0 deletions src/JsonApi/Serializer/EntrypointNormalizer.php
Expand Up @@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $data instanceof Entrypoint;
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? [Entrypoint::class => true] : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
14 changes: 14 additions & 0 deletions src/JsonApi/Serializer/ErrorNormalizer.php
Expand Up @@ -67,8 +67,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
}

public function getSupportedTypes($format): array
{
if (self::FORMAT === $format) {
return [
\Exception::class => true,
FlattenException::class => true,
];
}

return [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return true;
}
}
5 changes: 5 additions & 0 deletions src/JsonApi/Serializer/ItemNormalizer.php
Expand Up @@ -65,6 +65,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*/
Expand Down
14 changes: 14 additions & 0 deletions src/JsonApi/Serializer/ObjectNormalizer.php
Expand Up @@ -42,8 +42,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->decorated, 'getSupportedTypes')) {
return [
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
];
}

return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
}

Expand Down
5 changes: 5 additions & 0 deletions src/JsonLd/Serializer/ItemNormalizer.php
Expand Up @@ -58,6 +58,11 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
return self::FORMAT === $format ? parent::getSupportedTypes($format) : [];
}

/**
* {@inheritdoc}
*
Expand Down
14 changes: 14 additions & 0 deletions src/JsonLd/Serializer/ObjectNormalizer.php
Expand Up @@ -41,8 +41,22 @@ public function supportsNormalization(mixed $data, string $format = null, array
return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
}

public function getSupportedTypes($format): array
{
// @deprecated remove condition when support for symfony versions under 6.3 is dropped
if (!method_exists($this->decorated, 'getSupportedTypes')) {
return [
'*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(),
];
}

return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
}

public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod();
}

Expand Down

0 comments on commit db2cc95

Please sign in to comment.