|
17 | 17 | use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
|
18 | 18 | use ApiPlatform\JsonLd\AnonymousContextBuilderInterface;
|
19 | 19 | use ApiPlatform\JsonLd\ContextBuilderInterface;
|
| 20 | +use ApiPlatform\Metadata\Exception\ItemNotFoundException; |
20 | 21 | use ApiPlatform\Metadata\HttpOperation;
|
21 | 22 | use ApiPlatform\Metadata\IriConverterInterface;
|
22 | 23 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
23 | 24 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
|
| 25 | +use ApiPlatform\Metadata\Put; |
24 | 26 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
|
25 | 27 | use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
|
26 | 28 | use ApiPlatform\Metadata\ResourceClassResolverInterface;
|
@@ -148,9 +150,26 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
|
148 | 150 | throw new NotNormalizableValueException('Update is not allowed for this operation.');
|
149 | 151 | }
|
150 | 152 |
|
151 |
| - $context[self::OBJECT_TO_POPULATE] = $this->iriConverter->getResourceFromIri($data['@id'], $context + ['fetch_data' => true]); |
| 153 | + try { |
| 154 | + $context[self::OBJECT_TO_POPULATE] = $this->iriConverter->getResourceFromIri($data['@id'], $context + ['fetch_data' => true]); |
| 155 | + } catch (ItemNotFoundException $e) { |
| 156 | + $operation = $context['operation'] ?? null; |
| 157 | + if (!($operation instanceof Put && ($operation->getExtraProperties()['standard_put'] ?? false))) { |
| 158 | + throw $e; |
| 159 | + } |
| 160 | + } |
152 | 161 | }
|
153 | 162 |
|
154 | 163 | return parent::denormalize($data, $class, $format, $context);
|
155 | 164 | }
|
| 165 | + |
| 166 | + protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool |
| 167 | + { |
| 168 | + $allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString); |
| 169 | + if (\is_array($allowedAttributes) && ($context['api_denormalize'] ?? false)) { |
| 170 | + $allowedAttributes = array_merge($allowedAttributes, ['@id', '@type', '@context']); |
| 171 | + } |
| 172 | + |
| 173 | + return $allowedAttributes; |
| 174 | + } |
156 | 175 | }
|
0 commit comments