1515
1616use ApiPlatform \Metadata \Exception \InvalidArgumentException ;
1717use ApiPlatform \Metadata \HttpOperation ;
18- use ApiPlatform \Metadata \IriConverterInterface ;
1918use ApiPlatform \Metadata \Operation ;
20- use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
21- use ApiPlatform \Metadata \Property \Factory \PropertyNameCollectionFactoryInterface ;
22- use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
23- use ApiPlatform \Metadata \ResourceAccessCheckerInterface ;
24- use ApiPlatform \Metadata \ResourceClassResolverInterface ;
2519use ApiPlatform \Metadata \UrlGeneratorInterface ;
26- use Psr \Log \LoggerInterface ;
27- use Psr \Log \NullLogger ;
28- use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
2920use Symfony \Component \Serializer \Exception \NotNormalizableValueException ;
30- use Symfony \Component \Serializer \Mapping \Factory \ClassMetadataFactoryInterface ;
31- use Symfony \Component \Serializer \NameConverter \NameConverterInterface ;
3221
3322/**
3423 * Shared functionality for generic item normalization and denormalization.
3928 */
4029trait ItemNormalizerTrait
4130{
42- private readonly LoggerInterface $ logger ;
43-
44- public function __construct (PropertyNameCollectionFactoryInterface $ propertyNameCollectionFactory , PropertyMetadataFactoryInterface $ propertyMetadataFactory , IriConverterInterface $ iriConverter , ResourceClassResolverInterface $ resourceClassResolver , ?PropertyAccessorInterface $ propertyAccessor = null , ?NameConverterInterface $ nameConverter = null , ?ClassMetadataFactoryInterface $ classMetadataFactory = null , ?LoggerInterface $ logger = null , ?ResourceMetadataCollectionFactoryInterface $ resourceMetadataFactory = null , ?ResourceAccessCheckerInterface $ resourceAccessChecker = null , array $ defaultContext = [], protected ?TagCollectorInterface $ tagCollector = null )
45- {
46- parent ::__construct ($ propertyNameCollectionFactory , $ propertyMetadataFactory , $ iriConverter , $ resourceClassResolver , $ propertyAccessor , $ nameConverter , $ classMetadataFactory , $ defaultContext , $ resourceMetadataFactory , $ resourceAccessChecker , $ tagCollector );
47-
48- $ this ->logger = $ logger ?: new NullLogger ();
49- }
50-
5131 /**
5232 * {@inheritdoc}
5333 *
@@ -56,7 +36,7 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName
5636 public function denormalize (mixed $ data , string $ type , ?string $ format = null , array $ context = []): mixed
5737 {
5838 // Avoid issues with proxies if we populated the object
59- if (isset ($ data ['id ' ]) && !isset ($ context [self ::OBJECT_TO_POPULATE ])) {
39+ if (isset ($ data ['id ' ]) && !isset ($ context [AbstractItemNormalizer ::OBJECT_TO_POPULATE ])) {
6040 if (isset ($ context ['api_allow_update ' ]) && true !== $ context ['api_allow_update ' ]) {
6141 throw new NotNormalizableValueException ('Update is not allowed for this operation. ' );
6242 }
@@ -79,7 +59,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
7959 private function updateObjectToPopulate (array $ data , array &$ context ): bool
8060 {
8161 try {
82- $ context [self ::OBJECT_TO_POPULATE ] = $ this ->iriConverter ->getResourceFromIri ((string ) $ data ['id ' ], $ context + ['fetch_data ' => true ]);
62+ $ context [AbstractItemNormalizer ::OBJECT_TO_POPULATE ] = $ this ->iriConverter ->getResourceFromIri ((string ) $ data ['id ' ], $ context + ['fetch_data ' => true ]);
8363
8464 return true ;
8565 } catch (InvalidArgumentException ) {
@@ -96,7 +76,7 @@ private function updateObjectToPopulate(array $data, array &$context): bool
9676 $ uriVariables = $ this ->getContextUriVariables ($ data , $ operation , $ context );
9777 $ iri = $ this ->iriConverter ->getIriFromResource ($ context ['resource_class ' ], UrlGeneratorInterface::ABS_PATH , $ operation , ['uri_variables ' => $ uriVariables ]);
9878
99- $ context [self ::OBJECT_TO_POPULATE ] = $ this ->iriConverter ->getResourceFromIri ($ iri , $ context + ['fetch_data ' => true ]);
79+ $ context [AbstractItemNormalizer ::OBJECT_TO_POPULATE ] = $ this ->iriConverter ->getResourceFromIri ($ iri , $ context + ['fetch_data ' => true ]);
10080 }
10181
10282 return false ;
0 commit comments