Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::getPayload

Gets the decoded form or json request body.

Throws

JsonException When the body cannot be decoded to an array

File

vendor/symfony/http-foundation/Request.php, line 1449

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getPayload() : InputBag {
    if ($this->request
        ->count()) {
        return clone $this->request;
    }
    if ('' === ($content = $this->getContent())) {
        return new InputBag([]);
    }
    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 new InputBag($content);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal