PHP Class Phly\Http\ServerRequest

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.
Inheritance: implements Psr\Http\Message\ServerRequestInterface, use trait MessageTrait, use trait RequestTrait
Datei anzeigen Open project: phly/http Class Usage Examples

Public Methods

Method Description
__construct ( array $serverParams = [], array $uploadedFiles = [], null | string $uri = null, null | string $method = null, string | resource | Psr\Http\Message\StreamInterface $body = 'php://input', array $headers = [] )
getAttribute ( $attribute, $default = null )
getAttributes ( )
getCookieParams ( )
getMethod ( ) : string Proxy to receive the request method.
getParsedBody ( )
getQueryParams ( )
getServerParams ( )
getUploadedFiles ( )
withAttribute ( $attribute, $value )
withCookieParams ( array $cookies )
withMethod ( string $method ) : self Set the request method.
withParsedBody ( $data )
withQueryParams ( array $query )
withUploadedFiles ( array $uploadedFiles )
withoutAttribute ( $attribute )

Private Methods

Method Description
getStream ( string | resource | Psr\Http\Message\StreamInterface $stream ) : void Set the body stream
validateUploadedFiles ( array $uploadedFiles ) Recursively validate the structure in an uploaded files array.

Method Details

__construct() public method

public __construct ( array $serverParams = [], array $uploadedFiles = [], null | string $uri = null, null | string $method = null, string | resource | Psr\Http\Message\StreamInterface $body = 'php://input', array $headers = [] )
$serverParams array Server parameters, typically from $_SERVER
$uploadedFiles array Upload file information, a tree of UploadedFiles
$uri null | string URI for the request, if any.
$method null | string HTTP method for the request, if any.
$body string | resource | Psr\Http\Message\StreamInterface Message body, if any.
$headers array Headers for the message, if any.

getAttribute() public method

public getAttribute ( $attribute, $default = null )

getAttributes() public method

public getAttributes ( )

getCookieParams() public method

public getCookieParams ( )

getMethod() public method

This overrides the parent functionality to ensure the method is never empty; if no method is present, it returns 'GET'.
public getMethod ( ) : string
return string

getParsedBody() public method

public getParsedBody ( )

getQueryParams() public method

public getQueryParams ( )

getServerParams() public method

public getServerParams ( )

getUploadedFiles() public method

public getUploadedFiles ( )

withAttribute() public method

public withAttribute ( $attribute, $value )

withCookieParams() public method

public withCookieParams ( array $cookies )
$cookies array

withMethod() public method

Unlike the regular Request implementation, the server-side normalizes the method to uppercase to ensure consistency and make checking the method simpler. This methods returns a new instance.
public withMethod ( string $method ) : self
$method string
return self

withParsedBody() public method

public withParsedBody ( $data )

withQueryParams() public method

public withQueryParams ( array $query )
$query array

withUploadedFiles() public method

public withUploadedFiles ( array $uploadedFiles )
$uploadedFiles array

withoutAttribute() public method

public withoutAttribute ( $attribute )