Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14b02d1

Browse files
committed
add compat layer to listeners
1 parent 6fb747d commit 14b02d1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Symfony/EventListener/DeserializeListener.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Metadata\HttpOperation;
1717
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
1818
use ApiPlatform\State\ProviderInterface;
19+
use ApiPlatform\State\Provider\DeserializeProvider;
1920
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
2021
use ApiPlatform\State\Util\RequestAttributesExtractor;
2122
use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -65,6 +66,16 @@ public function onKernelRequest(RequestEvent $event): void
6566
$operation = $operation->withDeserialize(\in_array($method, ['POST', 'PUT', 'PATCH'], true));
6667
}
6768

69+
$denormalizationContext = $operation->getDenormalizationContext();
70+
if ($operation->canDeserialize() && !isset($denormalizationContext[DeserializeProvider::ASSIGN_OBJECT_TO_POPULATE])) {
71+
$method = $operation->getMethod();
72+
$assignObjectToPopulate = 'POST' === $method
73+
|| 'PATCH' === $method
74+
|| ('PUT' === $method && !($operation->getExtraProperties()['standard_put'] ?? true));
75+
76+
$operation = $operation->withDenormalizationContext($denormalizationContext + [DeserializeProvider::ASSIGN_OBJECT_TO_POPULATE => $assignObjectToPopulate]);
77+
}
78+
6879
if (!$operation->canDeserialize()) {
6980
return;
7081
}

0 commit comments

Comments
 (0)