-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add forward and backward compatibility to ProblemExceptionNormalizer
- Loading branch information
1 parent
f4cfa95
commit 0072174
Showing
2 changed files
with
42 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the OpenapiBundle package. | ||
* | ||
* (c) Niels Nijens <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nijens\OpenapiBundle\ExceptionHandling\Normalizer; | ||
|
||
use Nijens\OpenapiBundle\NijensOpenapiBundle; | ||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface as BaseNormalizerInterface; | ||
|
||
/* | ||
* Ensures compatibility with both Symfony versions 5.4 and 7.0. | ||
*/ | ||
if (NijensOpenapiBundle::getSymfonyVersion() < 60100) { | ||
interface NormalizerInterface extends ContextAwareNormalizerInterface | ||
{ | ||
} | ||
} else { | ||
interface NormalizerInterface extends BaseNormalizerInterface | ||
{ | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; | ||
use Symfony\Component\Serializer\Exception\InvalidArgumentException; | ||
use Symfony\Component\Serializer\Exception\LogicException; | ||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Throwable; | ||
|
@@ -27,7 +26,7 @@ | |
* | ||
* @author Niels Nijens <[email protected]> | ||
*/ | ||
final class ProblemExceptionNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface | ||
final class ProblemExceptionNormalizer implements NormalizerInterface, NormalizerAwareInterface | ||
{ | ||
use NormalizerAwareTrait; | ||
|
||
|
@@ -43,6 +42,9 @@ public function __construct(bool $debug = false) | |
$this->debug = $debug; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function normalize($object, $format = null, array $context = []) | ||
{ | ||
if ($object instanceof ProblemExceptionInterface === false) { | ||
|
@@ -71,6 +73,13 @@ public function supportsNormalization($data, $format = null, array $context = [] | |
return $data instanceof ProblemExceptionInterface; | ||
} | ||
|
||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
ProblemExceptionInterface::class => false, | ||
]; | ||
} | ||
|
||
private function removeDetailsToPreventInformationDisclosure(ProblemExceptionInterface $object, array &$data): void | ||
{ | ||
if ($this->debug) { | ||
|