diff --git a/src/Serializer/BigNumberNormalizer.php b/src/Serializer/BigNumberNormalizer.php index 1f310810..87619849 100644 --- a/src/Serializer/BigNumberNormalizer.php +++ b/src/Serializer/BigNumberNormalizer.php @@ -21,13 +21,12 @@ namespace App\Serializer; use Brick\Math\BigNumber; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * @see \App\Tests\Serializer\BigNumberNormalizerTest */ -class BigNumberNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface +class BigNumberNormalizer implements NormalizerInterface { public function supportsNormalization($data, string $format = null, array $context = []): bool @@ -44,8 +43,10 @@ class BigNumberNormalizer implements NormalizerInterface, CacheableSupportsMetho return (string) $object; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format) { - return true; + return [ + BigNumber::class => true, + ]; } } \ No newline at end of file diff --git a/src/Serializer/PartNormalizer.php b/src/Serializer/PartNormalizer.php index 634d6335..67b4066f 100644 --- a/src/Serializer/PartNormalizer.php +++ b/src/Serializer/PartNormalizer.php @@ -27,16 +27,20 @@ use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Pricedetail; use Brick\Math\BigDecimal; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; /** * @see \App\Tests\Serializer\PartNormalizerTest */ -class PartNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface +class PartNormalizer implements NormalizerInterface, DenormalizerInterface { + private const DENORMALIZE_KEY_MAPPING = [ 'notes' => 'comment', 'quantity' => 'instock', @@ -47,7 +51,10 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach 'storage_location' => 'storelocation', ]; - public function __construct(private readonly ObjectNormalizer $normalizer, private readonly StructuralElementFromNameDenormalizer $locationDenormalizer) + public function __construct( + private readonly StructuralElementFromNameDenormalizer $locationDenormalizer, + #[Autowire(service: ObjectNormalizer::class)] + private readonly NormalizerInterface $normalizer) { } @@ -166,9 +173,11 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach return $object; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format) { //Must be false, because we rely on is_array($data) in supportsDenormalization() - return false; + return [ + Part::class => false, + ]; } } \ No newline at end of file diff --git a/src/Serializer/StructuralElementDenormalizer.php b/src/Serializer/StructuralElementDenormalizer.php index 4212fd5d..c5130ef4 100644 --- a/src/Serializer/StructuralElementDenormalizer.php +++ b/src/Serializer/StructuralElementDenormalizer.php @@ -23,19 +23,25 @@ namespace App\Serializer; use App\Entity\Base\AbstractStructuralDBElement; use App\Repository\StructuralDBElementRepository; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; +use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; /** * @see \App\Tests\Serializer\StructuralElementDenormalizerTest */ -class StructuralElementDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface +class StructuralElementDenormalizer implements DenormalizerInterface { private array $object_cache = []; - public function __construct(private readonly ObjectNormalizer $normalizer, private readonly EntityManagerInterface $entityManager) + public function __construct( + private readonly EntityManagerInterface $entityManager, + #[Autowire(service: ObjectNormalizer::class)] + private readonly DenormalizerInterface $denormalizer) { } @@ -50,7 +56,7 @@ class StructuralElementDenormalizer implements DenormalizerInterface, CacheableS public function denormalize($data, string $type, string $format = null, array $context = []): ?AbstractStructuralDBElement { /** @var AbstractStructuralDBElement $deserialized_entity */ - $deserialized_entity = $this->normalizer->denormalize($data, $type, $format, $context); + $deserialized_entity = $this->denormalizer->denormalize($data, $type, $format, $context); //Check if we already have the entity in the database (via path) /** @var StructuralDBElementRepository $repo */ @@ -81,8 +87,11 @@ class StructuralElementDenormalizer implements DenormalizerInterface, CacheableS return $deserialized_entity; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(): array { - return false; + //Must be false, because we use in_array in supportsDenormalization + return [ + AbstractStructuralDBElement::class => false, + ]; } } \ No newline at end of file diff --git a/src/Serializer/StructuralElementFromNameDenormalizer.php b/src/Serializer/StructuralElementFromNameDenormalizer.php index c5dbfdf2..670bcdc1 100644 --- a/src/Serializer/StructuralElementFromNameDenormalizer.php +++ b/src/Serializer/StructuralElementFromNameDenormalizer.php @@ -29,7 +29,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; /** * @see \App\Tests\Serializer\StructuralElementFromNameDenormalizerTest */ -class StructuralElementFromNameDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface +class StructuralElementFromNameDenormalizer implements DenormalizerInterface { public function __construct(private readonly EntityManagerInterface $em) { @@ -67,9 +67,11 @@ class StructuralElementFromNameDenormalizer implements DenormalizerInterface, Ca return end($elements); } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format) { - //Must be false, because we do an is_string check on data in supportsDenormalization - return false; + //Cachable value Must be false, because we do an is_string check on data in supportsDenormalization + return [ + AbstractStructuralDBElement::class => false + ]; } } \ No newline at end of file diff --git a/src/Serializer/StructuralElementNormalizer.php b/src/Serializer/StructuralElementNormalizer.php index f71a56d5..c1931ffe 100644 --- a/src/Serializer/StructuralElementNormalizer.php +++ b/src/Serializer/StructuralElementNormalizer.php @@ -21,16 +21,22 @@ namespace App\Serializer; use App\Entity\Base\AbstractStructuralDBElement; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; /** * @see \App\Tests\Serializer\StructuralElementNormalizerTest */ -class StructuralElementNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface +class StructuralElementNormalizer implements NormalizerInterface { - public function __construct(private readonly ObjectNormalizer $normalizer) + public function __construct( + #[Autowire(service: ObjectNormalizer::class)] + private NormalizerInterface $normalizer + ) { } @@ -57,8 +63,10 @@ class StructuralElementNormalizer implements NormalizerInterface, CacheableSuppo return $data; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format) { - return true; + return [ + AbstractStructuralDBElement::class => true, + ]; } } \ No newline at end of file diff --git a/src/Validator/Constraints/ValidThemeValidator.php b/src/Validator/Constraints/ValidThemeValidator.php index f83bb500..03e6212f 100644 --- a/src/Validator/Constraints/ValidThemeValidator.php +++ b/src/Validator/Constraints/ValidThemeValidator.php @@ -30,7 +30,7 @@ class ValidThemeValidator extends ConstraintValidator { } - public function validate($value, Constraint $constraint) + public function validate($value, Constraint $constraint): void { if (!$constraint instanceof ValidTheme) { throw new UnexpectedTypeException($constraint, ValidTheme::class); diff --git a/tests/Serializer/StructuralElementDenormalizerTest.php b/tests/Serializer/StructuralElementDenormalizerTest.php index 624b30d4..be0a9e61 100644 --- a/tests/Serializer/StructuralElementDenormalizerTest.php +++ b/tests/Serializer/StructuralElementDenormalizerTest.php @@ -37,11 +37,6 @@ class StructuralElementDenormalizerTest extends WebTestCase $this->service = self::getContainer()->get(StructuralElementDenormalizer::class); } - public function testHasCacheableSupportsMethod(): void - { - $this->assertFalse($this->service->hasCacheableSupportsMethod()); - } - public function testSupportsDenormalization(): void { $this->assertFalse($this->service->supportsDenormalization('doesnt_matter', Category::class, 'json', ['groups' => ['import']]));