function Request::toArray
Gets the request body decoded as array, typically from a JSON payload.
Throws
JsonException When the body cannot be decoded to an array
See also
getPayload() for portability between content types
File
-
vendor/
symfony/ http-foundation/ Request.php, line 1479
Class
- Request
- Request represents an HTTP request.
Namespace
Symfony\Component\HttpFoundationCode
public function toArray() : array {
if ('' === ($content = $this->getContent())) {
throw new JsonException('Request body is empty.');
}
try {
$content = json_decode($content, true, 512, \JSON_BIGINT_AS_STRING | \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new JsonException('Could not decode request body.', $e->getCode(), $e);
}
if (!\is_array($content)) {
throw new JsonException(\sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
}
return $content;
}