Skip to content

Commit

Permalink
Merge pull request #8 from KnpLabs/feat/add-x-www-form-urlencoded-sup…
Browse files Browse the repository at this point in the history
…port

feat: add x-www-form-urlencoded support
  • Loading branch information
ErwannLeRoux authored Jul 27, 2023
2 parents 3952d15 + 48d9fa9 commit d0c8295
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RequestHandler
private const CONTENT_TYPES = [
'application/json',
'application/json;charset=utf-8',
'application/x-www-form-urlencoded',
];

private Collection $schemas;
Expand Down Expand Up @@ -53,11 +54,11 @@ public function extractJson(Request $request, string $schemaClass)
);
}

/** @var string */
$content = $request->getContent(false);

/** @var T */
$data = json_decode($content, true, flags: JSON_THROW_ON_ERROR);
$data = match ($mediaType) {
'application/x-www-form-urlencoded' => $request->request->all(),
default => json_decode((string) $request->getContent(false), true, flags: JSON_THROW_ON_ERROR),
};

$errors = $this->validator->validate($data, $this->schemas->get($schemaClass));

Expand Down

0 comments on commit d0c8295

Please sign in to comment.