Skip to content

Commit

Permalink
chore: replace Request::getContentType with `Request::getContentTyp…
Browse files Browse the repository at this point in the history
…eFormat` if available (#5325)
  • Loading branch information
Mathieu authored Jan 12, 2023
1 parent d338741 commit ff02d4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/GraphQl/Action/EntrypointAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ private function parseRequest(Request $request): array
return [$query, $operationName, $variables];
}

if ('json' === $request->getContentType()) {
// TODO remove call to getContentType() when requiring symfony/http-foundation ≥ 6.2
$contentTypeFormat = method_exists($request, 'getContentTypeFormat')
? $request->getContentTypeFormat()
: $request->getContentType();

if ('json' === $contentTypeFormat) {
return $this->parseData($query, $operationName, $variables, $request->getContent());
}

if ('graphql' === $request->getContentType()) {
if ('graphql' === $contentTypeFormat) {
$query = $request->getContent();
}

if (\in_array($request->getContentType(), ['multipart', 'form'], true)) {
if (\in_array($contentTypeFormat, ['multipart', 'form'], true)) {
return $this->parseMultipartRequest($query, $operationName, $variables, $request->request->all(), $request->files->all());
}

Expand Down
9 changes: 7 additions & 2 deletions src/Serializer/SerializerContextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function createFromRequest(Request $request, bool $normalization, array $
throw new RuntimeException('Request attributes are not valid.');
}

// TODO remove call to getContentType() when requiring symfony/http-foundation ≥ 6.2
$contentTypeFormat = method_exists($request, 'getContentTypeFormat')
? $request->getContentTypeFormat()
: $request->getContentType();

// TODO: 3.0 change the condition to remove the ResourceMetadataFactorym only used to skip null values
if (
$this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface
Expand Down Expand Up @@ -86,7 +91,7 @@ public function createFromRequest(Request $request, bool $normalization, array $
}
}

if ('csv' === $request->getContentType()) {
if ('csv' === $contentTypeFormat) {
$context[CsvEncoder::AS_COLLECTION_KEY] = false;
}
}
Expand Down Expand Up @@ -124,7 +129,7 @@ public function createFromRequest(Request $request, bool $normalization, array $
}
}

if ('csv' === $request->getContentType()) {
if ('csv' === $contentTypeFormat) {
$context[CsvEncoder::AS_COLLECTION_KEY] = false;
}
}
Expand Down

0 comments on commit ff02d4e

Please sign in to comment.