Copied!

Server-side HTTP request

Extends the Request definition to add methods for accessing incoming data, specifically server parameters, cookies, matched path parameters, query string arguments, body parameters, and upload file information.

"Attributes" are discovered via decomposing the request (and usually specifically the URI path), and typically will be injected by the application.

Requests are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return a new instance that contains the changed state.

CloneableInstantiable
Methods
public __construct(string $method, $uri, array $headers = [], $body = NULL, string $version = '1.1', array $serverParams = [])
 
  • param string $method HTTP method
  • param string|\UriInterface $uri URI
  • param (string|string[])[] $headers Request headers
  • param string|resource|\StreamInterface|null $body Request body
  • param string $version Protocol version
  • param array $serverParams Typically the $_SERVER superglobal
public static fromGlobals() : Psr\Http\Message\ServerRequestInterface
 

Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER

public getAttribute( $attribute, $default = NULL)
 
  • return mixed
public getAttributes() : array
public GuzzleHttp\Psr7\Request::getBody() : Psr\Http\Message\StreamInterface
public getCookieParams() : array
public GuzzleHttp\Psr7\Request::getHeader( $header) : array
public GuzzleHttp\Psr7\Request::getHeaderLine( $header) : string
public GuzzleHttp\Psr7\Request::getHeaders() : array
public GuzzleHttp\Psr7\Request::getMethod() : string
public getParsedBody()
 
  • return array|object|null
public GuzzleHttp\Psr7\Request::getProtocolVersion() : string
public getQueryParams() : array
public GuzzleHttp\Psr7\Request::getRequestTarget() : string
public getServerParams() : array
public getUploadedFiles() : array
public GuzzleHttp\Psr7\Request::getUri() : Psr\Http\Message\UriInterface
public static getUriFromGlobals() : Psr\Http\Message\UriInterface
 

Get a Uri populated with values from $_SERVER.

public GuzzleHttp\Psr7\Request::hasHeader( $header) : bool
public static normalizeFiles(array $files) : array
 

Return an UploadedFile instance array.

  • param array $files An array which respect $_FILES structure
  • throws \InvalidArgumentException for unrecognized values
public GuzzleHttp\Psr7\Request::withAddedHeader( $header, $value) : Psr\Http\Message\MessageInterface
public withAttribute( $attribute, $value) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withBody(Psr\Http\Message\StreamInterface $body) : Psr\Http\Message\MessageInterface
public withCookieParams(array $cookies) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withHeader( $header, $value) : Psr\Http\Message\MessageInterface
public GuzzleHttp\Psr7\Request::withMethod( $method) : Psr\Http\Message\RequestInterface
public withoutAttribute( $attribute) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withoutHeader( $header) : Psr\Http\Message\MessageInterface
public withParsedBody( $data) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withProtocolVersion( $version) : Psr\Http\Message\MessageInterface
public withQueryParams(array $query) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withRequestTarget( $requestTarget) : Psr\Http\Message\RequestInterface
public withUploadedFiles(array $uploadedFiles) : Psr\Http\Message\ServerRequestInterface
public GuzzleHttp\Psr7\Request::withUri(Psr\Http\Message\UriInterface $uri, $preserveHost = false) : Psr\Http\Message\RequestInterface
Properties
private $attributes = []
 
  • var array
private $cookieParams = []
 
  • var array
private $parsedBody = NULL
 
  • var array|object|null
private $queryParams = []
 
  • var array
private $serverParams = NULL
 
  • var array
private $uploadedFiles = []
 
  • var array
Methods
private static createUploadedFileFromSpec(array $value)
 

Create and return an UploadedFile instance from a $_FILES specification.

If the specification represents an array of values, this method will delegate to normalizeNestedFileSpec() and return that return value.

  • param array $value $_FILES struct
  • return \UploadedFileInterface|\UploadedFileInterface[]
private static extractHostAndPortFromAuthority(string $authority) : array
private static normalizeNestedFileSpec(array $files = []) : array
 

Normalize an array of file specifications.

Loops through all nested files and returns a normalized array of UploadedFileInterface instances.

  • return \UploadedFileInterface[]
Methods
private static createUploadedFileFromSpec(array $value)
 

Create and return an UploadedFile instance from a $_FILES specification.

If the specification represents an array of values, this method will delegate to normalizeNestedFileSpec() and return that return value.

  • param array $value $_FILES struct
  • return \UploadedFileInterface|\UploadedFileInterface[]
private static extractHostAndPortFromAuthority(string $authority) : array
public static fromGlobals() : Psr\Http\Message\ServerRequestInterface
 

Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER

public static getUriFromGlobals() : Psr\Http\Message\UriInterface
 

Get a Uri populated with values from $_SERVER.

public static normalizeFiles(array $files) : array
 

Return an UploadedFile instance array.

  • param array $files An array which respect $_FILES structure
  • throws \InvalidArgumentException for unrecognized values
private static normalizeNestedFileSpec(array $files = []) : array
 

Normalize an array of file specifications.

Loops through all nested files and returns a normalized array of UploadedFileInterface instances.

  • return \UploadedFileInterface[]
© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration