Skip to content

Commit ffb3d0f

Browse files
tuanphpvnabluchet
authored andcommitted
Use object_to_populate constant in normalizers
1 parent c07b770 commit ffb3d0f

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/EventListener/DeserializeListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
2020
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
21+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
2122
use Symfony\Component\Serializer\SerializerInterface;
2223

2324
/**
@@ -61,7 +62,7 @@ public function onKernelRequest(GetResponseEvent $event)
6162

6263
$data = $request->attributes->get('data');
6364
if (null !== $data) {
64-
$context['object_to_populate'] = $data;
65+
$context[AbstractNormalizer::OBJECT_TO_POPULATE] = $data;
6566
}
6667

6768
$request->attributes->set(

src/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ public function supportsDenormalization($data, $type, $format = null)
9797
public function denormalize($data, $class, $format = null, array $context = [])
9898
{
9999
// Avoid issues with proxies if we populated the object
100-
if (isset($data['@id']) && !isset($context['object_to_populate'])) {
100+
if (isset($data['@id']) && !isset($context[self::OBJECT_TO_POPULATE])) {
101101
if (isset($context['api_allow_update']) && true !== $context['api_allow_update']) {
102102
throw new InvalidArgumentException('Update is not allowed for this operation.');
103103
}
104104

105-
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['@id'], $context + ['fetch_data' => true]);
105+
$context[self::OBJECT_TO_POPULATE] = $this->iriConverter->getItemFromIri($data['@id'], $context + ['fetch_data' => true]);
106106
}
107107

108108
return parent::denormalize($data, $class, $format, $context);

src/Serializer/ItemNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class ItemNormalizer extends AbstractItemNormalizer
3030
public function denormalize($data, $class, $format = null, array $context = [])
3131
{
3232
// Avoid issues with proxies if we populated the object
33-
if (isset($data['id']) && !isset($context['object_to_populate'])) {
33+
if (isset($data['id']) && !isset($context[self::OBJECT_TO_POPULATE])) {
3434
if (isset($context['api_allow_update']) && true !== $context['api_allow_update']) {
3535
throw new InvalidArgumentException('Update is not allowed for this operation.');
3636
}
@@ -44,7 +44,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
4444
private function updateObjectToPopulate(array $data, array &$context)
4545
{
4646
try {
47-
$context['object_to_populate'] = $this->iriConverter->getItemFromIri((string) $data['id'], $context + ['fetch_data' => true]);
47+
$context[self::OBJECT_TO_POPULATE] = $this->iriConverter->getItemFromIri((string) $data['id'], $context + ['fetch_data' => true]);
4848
} catch (InvalidArgumentException $e) {
4949
$identifier = null;
5050
foreach ($this->propertyNameCollectionFactory->create($context['resource_class'], $context) as $propertyName) {
@@ -58,7 +58,7 @@ private function updateObjectToPopulate(array $data, array &$context)
5858
throw $e;
5959
}
6060

61-
$context['object_to_populate'] = $this->iriConverter->getItemFromIri(sprintf('%s/%s', $this->iriConverter->getIriFromResourceClass($context['resource_class']), $data[$identifier]), $context + ['fetch_data' => true]);
61+
$context[self::OBJECT_TO_POPULATE] = $this->iriConverter->getItemFromIri(sprintf('%s/%s', $this->iriConverter->getIriFromResourceClass($context['resource_class']), $data[$identifier]), $context + ['fetch_data' => true]);
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)