Request
in package
implements
ServerRequestInterface
The request class is a component that allows developers to retrieve information about data that usually is delivered by the webserver. For example, get and post data are usually stored by this object in order to allow your app to use it.
Interfaces, Classes and Traits
- ServerRequestInterface
Table of Contents
- $attributes : mixed
- $body : StreamInterface
- $cookie : mixed
- Allows your app to maintain a copy of the COOKIE variable. This is especially useful when writing tests considering different requests as you will easily be able to swap the values.
- $get : Get
- Contains information what information was delivered via query parameters of the URL. This will be a special _GET object that will aid generating canonicals.
- $headers : Headers
- This object allows your app to conveniently access the HTTP headers. These will contain information like DNT or User agent that can be relevant to your application and alter the experience the user receives.
- $method : string
- The HTTP verb that is used to indicate what the server should do with the data it receives from the client application. This allows us to specifically route some things in the application.
- $post : mixed
- This contains a mixed version of _POST and _FILES that allows your app to conveniently use the data generated by this two sources in a single place.
- $serverParams : array<string|int, string>
- The server parameter array contains all the runtime information the server has about itself and the current request. Usually this data is directly originated from $_SERVER
- $uploads : array<string|int, array|\Psr\Http\Message\UploadedFileInterface>
- The array tree of uploads, this is a mix of UploadInterfaces and arrays. The application can the use the array to manipulate the uploaded file.
- $uri : UriInterface
- Contains data that can be retrieved out of the Path string of the URL. For example, the controller / action / object of the request or data about custom route parameters.
- $version : string
- The version of the HTTP protocol being used for this request.
- __construct() : mixed
- Creates a new Request. This object 'simulates' a link between the user and the Application. It allows you to retrieve the data the user has sent with the Request and therefore adapt the behavior of your application accordingly.
- getAttribute() : mixed
- getAttributes() : array<string|int, mixed>
- getBody() : StreamInterface
- Returns the content that is to be sent with the body. This is a string your application has to set beforehand.
- getCookieParams() : array<string|int, string>
- getHeader() : array<string|int, string>
- getHeaderLine() : string
- The header line represents the data that is being sent to the browser, some headers allow sending multiple values, separated by commas, which the client cannot receive unless we convert our arrays in comma separated strings.
- getHeaders() : mixed
- getMethod() : string
- Returns the name of the method used to request from this server. Currently we focus on supporting GET, POST, PUT, DELETE and OPTIONS
- getParsedBody() : array<string|int, mixed>
- getProtocolVersion() : string
- Returns the version of the HTTP protocol used to send this request. For PHP most of this is transparent when handling a request, so it's possible that this data is actually not properly poulated.
- getQueryParams() : array<string|int, mixed>
- Returns the array of query parameters (_GET) that the request was sent along with.
- getRange() : array<string|int, mixed>
- For ranged requests, this function provides a convenience access to the range data.
- getRequestTarget() : string
- Returns the request target. I am still not 100% certain what the request target is, it seems to be some kind of fallback that I am not certain how it works (apparently you can request wildcard data from some servers).
- getServerParams() : array<string|int, string>
- The server params function returns the equivalent of the _SERVER superglobal. We generally set the content of the variable to _SERVER but you may come across implementations that override it completely or partially.
- getUploadedFiles() : array<string|int, array|\Psr\Http\Message\UploadedFileInterface>
- Returns a tree of uploaded files. The tree contains arrays mixed with UploadedFileInterface objects that contain the actual metadata.
- getUri() : UriInterface
- Returns the URI used to request a resource from the server.
- hasHeader() : bool
- isPost() : bool
- Whether this request was posted.
- isRange() : bool
- If the request contains range information (the client only wishes to retrieve a subset of the resource), this endpoint will return true.
- withAddedHeader() : Request
- Returns a copy of the response, but with additional information on a header, which allows the user to push data onto the header.
- withAttribute() : ServerRequestInterface
- Override a single attribute that the server received. Please note that this method does not support nested access, so you cannot override a key in a nested attribute.
- withBody() : mixed
- withCookieParams() : mixed
- withHeader() : Request
- Returns a copy of the response, with the header that the user has added.
- withMethod() : mixed
- withoutAttribute() : Request
- Removes the attribute from the request.
- withoutHeader() : Request
- Returns a copy of the response, without the given header.
- withParsedBody() : Request
- withProtocolVersion() : mixed
- withQueryParams() : Request
- withRequestTarget() : Request
- In our service this is not implemented. Calling it has no effect
- withUploadedFiles() : mixed
- withUri() : ServerRequestInterface
- Override the request URI for the server.
Properties
$attributes
private
mixed
$attributes
$body
private
StreamInterface
$body
$cookie
Allows your app to maintain a copy of the COOKIE variable. This is especially useful when writing tests considering different requests as you will easily be able to swap the values.
private
mixed
$cookie
$get
Contains information what information was delivered via query parameters of the URL. This will be a special _GET object that will aid generating canonicals.
private
Get
$get
If you're writing an application/component that cannot guarantee having the request.replace_globals enabled you should use this rather than $_GET
$headers
This object allows your app to conveniently access the HTTP headers. These will contain information like DNT or User agent that can be relevant to your application and alter the experience the user receives.
private
Headers
$headers
$method
The HTTP verb that is used to indicate what the server should do with the data it receives from the client application. This allows us to specifically route some things in the application.
private
string
$method
$post
This contains a mixed version of _POST and _FILES that allows your app to conveniently use the data generated by this two sources in a single place.
private
mixed
$post
$serverParams
The server parameter array contains all the runtime information the server has about itself and the current request. Usually this data is directly originated from $_SERVER
private
array<string|int, string>
$serverParams
$uploads
The array tree of uploads, this is a mix of UploadInterfaces and arrays. The application can the use the array to manipulate the uploaded file.
private
array<string|int, array|\Psr\Http\Message\UploadedFileInterface>
$uploads
Tags
$uri
Contains data that can be retrieved out of the Path string of the URL. For example, the controller / action / object of the request or data about custom route parameters.
private
UriInterface
$uri
$version
The version of the HTTP protocol being used for this request.
private
string
$version
= '1.1'
Methods
__construct()
Creates a new Request. This object 'simulates' a link between the user and the Application. It allows you to retrieve the data the user has sent with the Request and therefore adapt the behavior of your application accordingly.
public
__construct(string $method, UriInterface $uri, Headers $headers, array<string|int, string> $cookies, array<string|int, string> $serverParams, StreamInterface $body) : mixed
[Notice] This function does NOT validate the data it receives and assumes it is correct. This is due to this code being executed every single time your app is invoked and therefore being required to be lightweight.
Parameters
- $method : string
- $uri : UriInterface
- $headers : Headers
- $cookies : array<string|int, string>
- $serverParams : array<string|int, string>
- $body : StreamInterface
Return values
mixed —getAttribute()
public
getAttribute(mixed $name[, mixed $default = null ]) : mixed
Parameters
- $name : mixed
- $default : mixed = null
Return values
mixed —getAttributes()
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getBody()
Returns the content that is to be sent with the body. This is a string your application has to set beforehand.
public
getBody() : StreamInterface
In case you're using Spitfire's Context object to manage the context the response will get the view it contains and render that before returning it.
Return values
StreamInterface —getCookieParams()
public
getCookieParams() : array<string|int, string>
Return values
array<string|int, string> —getHeader()
public
getHeader(string $name) : array<string|int, string>
Parameters
- $name : string
Return values
array<string|int, string> —getHeaderLine()
The header line represents the data that is being sent to the browser, some headers allow sending multiple values, separated by commas, which the client cannot receive unless we convert our arrays in comma separated strings.
public
getHeaderLine(string $name) : string
Parameters
- $name : string
Return values
string —getHeaders()
public
getHeaders() : mixed
Return values
mixed —getMethod()
Returns the name of the method used to request from this server. Currently we focus on supporting GET, POST, PUT, DELETE and OPTIONS
public
getMethod() : string
Return values
string —getParsedBody()
public
getParsedBody() : array<string|int, mixed>
Return values
array<string|int, mixed> —getProtocolVersion()
Returns the version of the HTTP protocol used to send this request. For PHP most of this is transparent when handling a request, so it's possible that this data is actually not properly poulated.
public
getProtocolVersion() : string
Return values
string —getQueryParams()
Returns the array of query parameters (_GET) that the request was sent along with.
public
getQueryParams() : array<string|int, mixed>
Return values
array<string|int, mixed> —getRange()
For ranged requests, this function provides a convenience access to the range data.
public
getRange() : array<string|int, mixed>
This method only supports ranges in Bytes
Return values
array<string|int, mixed> —getRequestTarget()
Returns the request target. I am still not 100% certain what the request target is, it seems to be some kind of fallback that I am not certain how it works (apparently you can request wildcard data from some servers).
public
getRequestTarget() : string
Return values
string —getServerParams()
The server params function returns the equivalent of the _SERVER superglobal. We generally set the content of the variable to _SERVER but you may come across implementations that override it completely or partially.
public
getServerParams() : array<string|int, string>
Return values
array<string|int, string> —getUploadedFiles()
Returns a tree of uploaded files. The tree contains arrays mixed with UploadedFileInterface objects that contain the actual metadata.
public
getUploadedFiles() : array<string|int, array|\Psr\Http\Message\UploadedFileInterface>
Tags
Return values
array<string|int, array|\Psr\Http\Message\UploadedFileInterface> —getUri()
Returns the URI used to request a resource from the server.
public
getUri() : UriInterface
Return values
UriInterface —hasHeader()
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
bool —isPost()
Whether this request was posted.
public
isPost() : bool
Return values
bool —isRange()
If the request contains range information (the client only wishes to retrieve a subset of the resource), this endpoint will return true.
public
isRange() : bool
Return values
bool —withAddedHeader()
Returns a copy of the response, but with additional information on a header, which allows the user to push data onto the header.
public
withAddedHeader(string $name, string|array<string|int, string> $value) : Request
Parameters
- $name : string
- $value : string|array<string|int, string>
Return values
Request —withAttribute()
Override a single attribute that the server received. Please note that this method does not support nested access, so you cannot override a key in a nested attribute.
public
withAttribute(mixed $name, mixed $value) : ServerRequestInterface
Parameters
- $name : mixed
- $value : mixed
Return values
ServerRequestInterface —withBody()
public
withBody(StreamInterface $body) : mixed
Parameters
- $body : StreamInterface
Return values
mixed —withCookieParams()
public
withCookieParams(array<string|int, string> $cookies) : mixed
Parameters
- $cookies : array<string|int, string>
Return values
mixed —withHeader()
Returns a copy of the response, with the header that the user has added.
public
withHeader(string $name, string|array<string|int, string> $value) : Request
Parameters
- $name : string
- $value : string|array<string|int, string>
Return values
Request —withMethod()
public
withMethod(mixed $method) : mixed
Parameters
- $method : mixed
Return values
mixed —withoutAttribute()
Removes the attribute from the request.
public
withoutAttribute(mixed $name) : Request
Parameters
- $name : mixed
Return values
Request —withoutHeader()
Returns a copy of the response, without the given header.
public
withoutHeader(string $name) : Request
Parameters
- $name : string
Return values
Request —withParsedBody()
public
withParsedBody(null|array<string|int, mixed> $data) : Request
Parameters
- $data : null|array<string|int, mixed>
Return values
Request —withProtocolVersion()
public
withProtocolVersion(mixed $version) : mixed
Parameters
- $version : mixed
Return values
mixed —withQueryParams()
public
withQueryParams(array<string|int, mixed> $query) : Request
Parameters
- $query : array<string|int, mixed>
Return values
Request —withRequestTarget()
In our service this is not implemented. Calling it has no effect
public
withRequestTarget(mixed $requestTarget) : Request
Parameters
- $requestTarget : mixed
Return values
Request —withUploadedFiles()
public
withUploadedFiles(array<string|int, array|\Psr\Http\Message\UploadedFileInterface> $uploadedFiles) : mixed
Parameters
- $uploadedFiles : array<string|int, array|\Psr\Http\Message\UploadedFileInterface>
Return values
mixed —withUri()
Override the request URI for the server.
public
withUri(UriInterface $uri[, mixed $preserveHost = false ]) : ServerRequestInterface
Parameters
- $uri : UriInterface
- $preserveHost : mixed = false