Skip to content

Commit

Permalink
Use AttributeLoader if available
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Dec 15, 2023
1 parent cdb6f10 commit 3d3635f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/VerbsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
Expand Down Expand Up @@ -64,9 +65,13 @@ public function packageRegistered()
$this->app->singleton(Serializer::class);

$this->app->singleton(PropertyNormalizer::class, function () {
return new PropertyNormalizer(
$loader = class_exists(AttributeLoader::class)
? new AttributeLoader()
: new AnnotationLoader();

return new PropertyNormalizer(
propertyTypeExtractor: new ReflectionExtractor(),
classDiscriminatorResolver: new ClassDiscriminatorFromClassMetadata(new ClassMetadataFactory(new AttributeLoader())),
classDiscriminatorResolver: new ClassDiscriminatorFromClassMetadata(new ClassMetadataFactory($loader)),
);
});

Expand Down

0 comments on commit 3d3635f

Please sign in to comment.