-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use defaults.extra_properties.skip_deprecated_exception_normalizers to skip these normalizers. fixes #5921
- Loading branch information
Showing
16 changed files
with
187 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
/** | ||
* Converts {@see \Exception} or {@see FlattenException} to a Hydra error representation. | ||
* | ||
* @deprecated | ||
* @deprecated we use ItemNormalizer instead | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
* @author Samuel ROZE <[email protected]> | ||
|
@@ -37,7 +37,7 @@ final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMet | |
public const TITLE = 'title'; | ||
private array $defaultContext = [self::TITLE => 'An error occurred']; | ||
|
||
public function __construct(private readonly UrlGeneratorInterface|LegacyUrlGeneratorInterface $urlGenerator, private readonly bool $debug = false, array $defaultContext = []) | ||
public function __construct(private readonly UrlGeneratorInterface|LegacyUrlGeneratorInterface $urlGenerator, private readonly bool $debug = false, array $defaultContext = [], private readonly ?NormalizerInterface $itemNormalizer = null) | ||
{ | ||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext); | ||
} | ||
|
@@ -47,7 +47,12 @@ public function __construct(private readonly UrlGeneratorInterface|LegacyUrlGene | |
*/ | ||
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null | ||
{ | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource.', __CLASS__)); | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource. We fallback on "api_platform.serializer.normalizer.item".', __CLASS__)); | ||
|
||
if ($this->itemNormalizer) { | ||
return $this->itemNormalizer->normalize($object, $format, $context); | ||
} | ||
|
||
$data = [ | ||
'@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'Error']), | ||
'@type' => 'hydra:Error', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
/** | ||
* Converts {@see \Exception} or {@see FlattenException} or to a JSON API error representation. | ||
* | ||
* @deprecated we use ItemNormalizer instead | ||
* | ||
* @author Héctor Hurtarte <[email protected]> | ||
*/ | ||
final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface | ||
|
@@ -34,7 +36,7 @@ final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMet | |
self::TITLE => 'An error occurred', | ||
]; | ||
|
||
public function __construct(private readonly bool $debug = false, array $defaultContext = []) | ||
public function __construct(private readonly bool $debug = false, array $defaultContext = [], private readonly ?NormalizerInterface $itemNormalizer = null) | ||
{ | ||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext); | ||
} | ||
|
@@ -44,7 +46,12 @@ public function __construct(private readonly bool $debug = false, array $default | |
*/ | ||
public function normalize(mixed $object, string $format = null, array $context = []): array | ||
{ | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource.', __CLASS__)); | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource. We fallback on "api_platform.serializer.normalizer.item".', __CLASS__)); | ||
|
||
if ($this->itemNormalizer) { | ||
return $this->itemNormalizer->normalize($object, $format, $context); | ||
} | ||
|
||
$data = [ | ||
'title' => $context[self::TITLE] ?? $this->defaultContext[self::TITLE], | ||
'description' => $this->getErrorMessage($object, $context, $this->debug), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
* Normalizes errors according to the API Problem spec (RFC 7807). | ||
* | ||
* @see https://tools.ietf.org/html/rfc7807 | ||
* @deprecated we use ItemNormalizer instead | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
|
@@ -36,7 +37,7 @@ final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMet | |
self::TITLE => 'An error occurred', | ||
]; | ||
|
||
public function __construct(private readonly bool $debug = false, array $defaultContext = []) | ||
public function __construct(private readonly bool $debug = false, array $defaultContext = [], private readonly ?NormalizerInterface $itemNormalizer = null) | ||
{ | ||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext); | ||
} | ||
|
@@ -46,7 +47,12 @@ public function __construct(private readonly bool $debug = false, array $default | |
*/ | ||
public function normalize(mixed $object, string $format = null, array $context = []): array | ||
{ | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource.', __CLASS__)); | ||
trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated in favor of using an Error resource. We fallback on "api_platform.serializer.normalizer.item".', __CLASS__)); | ||
|
||
if ($this->itemNormalizer) { | ||
return $this->itemNormalizer->normalize($object, $format, $context); | ||
} | ||
|
||
$data = [ | ||
'type' => $context[self::TYPE] ?? $this->defaultContext[self::TYPE], | ||
'title' => $context[self::TITLE] ?? $this->defaultContext[self::TITLE], | ||
|
@@ -69,12 +75,12 @@ public function supportsNormalization(mixed $data, string $format = null, array | |
return false; | ||
} | ||
|
||
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); | ||
return (self::FORMAT === $format || 'json' === $format) && ($data instanceof \Exception || $data instanceof FlattenException); | ||
} | ||
|
||
public function getSupportedTypes($format): array | ||
{ | ||
if (self::FORMAT === $format) { | ||
if (self::FORMAT === $format || 'json' === $format) { | ||
return [ | ||
\Exception::class => false, | ||
FlattenException::class => false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.