mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Fixed some serializer deprecations
This commit is contained in:
parent
219b57a362
commit
e57d6e508a
7 changed files with 51 additions and 27 deletions
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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']]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue