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

Breadcrumb

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

function Request::getContent

Same name in this branch
  1. 11.1.x vendor/symfony/browser-kit/Request.php \Symfony\Component\BrowserKit\Request::getContent()

Returns the request body content.

@psalm-return ($asResource is true ? resource : string)

Parameters

bool $asResource If true, a resource will be returned:

Return value

string|resource

3 calls to Request::getContent()
Request::getPayload in vendor/symfony/http-foundation/Request.php
Gets the decoded form or json request body.
Request::toArray in vendor/symfony/http-foundation/Request.php
Gets the request body decoded as array, typically from a JSON payload.
Request::__toString in vendor/symfony/http-foundation/Request.php

File

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

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getContent(bool $asResource = false) {
    $currentContentIsResource = \is_resource($this->content);
    if (true === $asResource) {
        if ($currentContentIsResource) {
            rewind($this->content);
            return $this->content;
        }
        // Content passed in parameter (test)
        if (\is_string($this->content)) {
            $resource = fopen('php://temp', 'r+');
            fwrite($resource, $this->content);
            rewind($resource);
            return $resource;
        }
        $this->content = false;
        return fopen('php://input', 'r');
    }
    if ($currentContentIsResource) {
        rewind($this->content);
        return stream_get_contents($this->content);
    }
    if (null === $this->content || false === $this->content) {
        $this->content = file_get_contents('php://input');
    }
    return $this->content;
}

API Navigation

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