Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d3a290f

Browse filesBrowse files
committed
apply feedbacks
1 parent 64beabd commit d3a290f
Copy full SHA for d3a290f

File tree

2 files changed

+14
-14
lines changed
Filter options

2 files changed

+14
-14
lines changed

‎src/Symfony/Component/HttpKernel/Attribute/MapRequestPayload.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Attribute/MapRequestPayload.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
class MapRequestPayload extends ValueResolver
2424
{
2525
public function __construct(
26-
public readonly array|string|null $format = null,
27-
public readonly array $context = [],
28-
public readonly string|GroupSequence|array|null|false $groups = null,
26+
public readonly array|string|null $acceptedFormats = null,
27+
public readonly array $deserializationContext = [],
28+
public readonly string|GroupSequence|array|null $validationGroups = null,
2929
string $resolver = RequestPayloadValueResolver::class,
3030
) {
3131
parent::__construct($resolver);

‎src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
9292
}
9393

9494
if (null !== $payload) {
95-
$violations->addAll($this->validator->validate($payload, null, $attributes[0]->groups ?? null));
95+
$violations->addAll($this->validator->validate($payload, null, $attributes[0]->validationGroups ?? null));
9696
}
9797

9898
if (\count($violations)) {
@@ -125,29 +125,29 @@ private function mapQueryString(Request $request, ArgumentMetadata $argument, Ma
125125

126126
private function mapRequestPayload(Request $request, ArgumentMetadata $argument, MapRequestPayload $attribute): ?object
127127
{
128-
if ($data = $request->request->all()) {
129-
return $this->serializer->denormalize($data, $argument->getType(), null, self::CONTEXT_DENORMALIZE + $attribute->context);
128+
if (null === $format = $request->getContentTypeFormat()) {
129+
throw new HttpException(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, 'Unsupported format.');
130130
}
131131

132-
if ('' === $data = $request->getContent()) {
133-
return null;
132+
$acceptedFormats = \is_string($attribute->acceptedFormats) ? [$attribute->acceptedFormats] : $attribute->acceptedFormats;
133+
if (\is_array($attribute->acceptedFormats) && !\in_array($format, $acceptedFormats, true)) {
134+
throw new HttpException(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', $acceptedFormats), $format));
134135
}
135136

136-
if (null === $format = $request->getContentTypeFormat()) {
137-
throw new HttpException(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, 'Unsupported format.');
137+
if ($data = $request->request->all()) {
138+
return $this->serializer->denormalize($data, $argument->getType(), null, self::CONTEXT_DENORMALIZE + $attribute->deserializationContext);
138139
}
139140

140-
$acceptedFormats = \is_string($attribute->format) ? [$attribute->format] : $attribute->format;
141-
if (\is_array($attribute->format) && !\in_array($format, $acceptedFormats, true)) {
142-
throw new HttpException(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', $acceptedFormats), $format));
141+
if ('' === $data = $request->getContent()) {
142+
return null;
143143
}
144144

145145
if ('form' === $format) {
146146
throw new HttpException(Response::HTTP_BAD_REQUEST, 'Request payload contains invalid "form" data.');
147147
}
148148

149149
try {
150-
return $this->serializer->deserialize($data, $argument->getType(), $format, self::CONTEXT_DESERIALIZE + $attribute->context);
150+
return $this->serializer->deserialize($data, $argument->getType(), $format, self::CONTEXT_DESERIALIZE + $attribute->deserializationContext);
151151
} catch (UnsupportedFormatException $e) {
152152
throw new HttpException(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, sprintf('Unsupported format: "%s".', $format), $e);
153153
} catch (NotEncodableValueException $e) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.