You are here

public function Request::getContent in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-foundation/Request.php \Symfony\Component\HttpFoundation\Request::getContent()
  2. 8 vendor/symfony/browser-kit/Request.php \Symfony\Component\BrowserKit\Request::getContent()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Request.php \Symfony\Component\HttpFoundation\Request::getContent()

Returns the request body content.

Parameters

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

Return value

string|resource The request body content or a resource to read the body stream.

Throws

\LogicException

1 call to Request::getContent()
Request::__toString in vendor/symfony/http-foundation/Request.php
Returns the request as a string.
1 method overrides Request::getContent()
RequestContentProxy::getContent in vendor/symfony/http-foundation/Tests/RequestTest.php
Returns the request body content.

File

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

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getContent($asResource = false) {
  $currentContentIsResource = is_resource($this->content);
  if (PHP_VERSION_ID < 50600 && false === $this->content) {
    throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
  }
  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', 'rb');
  }
  if ($currentContentIsResource) {
    rewind($this->content);
    return stream_get_contents($this->content);
  }
  if (null === $this->content) {
    $this->content = file_get_contents('php://input');
  }
  return $this->content;
}