Trait ServerRequestTrait
Representation of an incoming, server-side HTTP request.
Per the HTTP specification, this interface includes properties for each of the following:
- Protocol version
- HTTP method
- URI
- Headers
- Message body
Additionally, it encapsulates all data as it has arrived at the application from the CGI and/or PHP environment, including:
- The values represented in $_SERVER.
- Any cookies provided (generally via $_COOKIE)
- Query string arguments (generally via $_GET, or as parsed via parse_str())
- Upload files, if any (as represented by $_FILES)
- Deserialized body parameters (generally from $_POST)
$_SERVER values MUST be treated as immutable, as they represent application state at the time of request; as such, no methods are provided to allow modification of those values. The other values provide such methods, as they can be restored from $_SERVER or the request body, and may need treatment during the application (e.g., body parameters may be deserialized based on content type).
Additionally, this interface recognizes the utility of introspecting a request to derive and match additional parameters (e.g., via URI path matching, decrypting cookie values, deserializing non-form-encoded body content, matching authorization headers to users, etc). These parameters are stored in an "attributes" property.
Requests are considered immutable; all methods that might change state MUST be implemented such that they retain the internal state of the current message and return an instance that contains the changed state.
- oroboros\core\traits\libraries\request\ServerRequestTrait uses oroboros\core\traits\libraries\request\RequestTrait
Direct Known Users
oroboros\core\abstracts\libraries\request\AbstractServerRequest
Indirect Known Users
Package: oroboros\core\psr7
Category: traits
License: The MIT License (MIT)
Author: Brian Dayhoff mopsyd@me.com
Version: 0.2.4
Since: 0.2.4-alpha
Link: bitbucket.org/oroborosframework/oroboros-core/wiki/development/api/traits.md
Satisfies: \oroboros\core\interfaces\contract\libraries\request\ServerRequestContract
Satisfies: \Psr\Http\Message\ServerRequestInterface
Located at core/traits/libraries/request/ServerRequestTrait.php
Methods summary
public
|
#
__construct( scalar|resource|Psr\Http\Message\StreamInterface $body, array $headers = null, type $protocol = null, string $host = null, string $uri = null, string $method = null, array $params = array(), array $cookies = array(), array $query = array(), array $files = array(), array $parsed = array(), array $attributes = array() )
|
public static
|
#
create( array $params = array(), array $cookies = array(), array $query = array(), array $files = array(), array $parsed = array(), array $attributes = array() )
|
public static
|
#
fromGlobals( )
|
public
array
|
|
public
array
|
|
public
static
|
|
public
array
|
|
public
static
|
|
public
array
|
|
public
static
|
#
withUploadedFiles( array $uploadedFiles )
Create a new instance with the specified uploaded files. |
public
null|array|object
|
|
public
static
|
|
public
mixed[]
|
|
public
mixed
|
|
public
static
|
#
withAttribute( string $name, mixed $value )
Return an instance with the specified derived request attribute. |
public
static
|
#
withoutAttribute( string $name )
Return an instance that removes the specified derived request attribute. |
protected
|
#
_initializeServerRequest( array $body, array $headers = null, array $protocol = null, array $host = null, array $uri = null, array $method = null, array $params = array(), array $cookies = array(), array $query = array(), array $files = array(), array $parsed = array(), array $attributes = array() )
|
private
|
#
_validateServerRequestParams( string $params )
Validates the params. Params must be an array compatible with the structure of the $_SERVER superglobal. |
private
|
#
_validateServerRequestCookies( string $cookies )
Validates the cookies. Cookies must be an array compatible with the structure of the $_COOKIES superglobal. |
private
|
#
_validateServerRequestQuery( string $query )
Validates the cookies. Cookies must be an array compatible with the structure of the $_GET superglobal. |
private
|
#
_validateServerRequestFiles( string $files )
Validates the files. Files must be an array compatible with the structure of the $_FILES superglobal. |
private
|
#
_validateServerRequestParsed( string $parsed )
Validates the parsed values. Parsed values must be an array compatible with the structure of the $_POST superglobal. |
private
|
#
_validateServerRequestAttributes( string $attributes )
Validates the attributes. Attributes must be an array compatible with the structure of the $_POST superglobal. |
private
|
#
_setServerRequestParams( string $params )
Creates an object that represents the provided params, and stores it internally. |
private
|
#
_setServerRequestCookies( string $cookies )
Creates an object that represents the cookies, and stores it internally. |
private
|
#
_setServerRequestQuery( string $query )
Creates an object that represents the query, and stores it internally. |
private
|
#
_setServerRequestFiles( string $files )
Creates an object that represents the uploaded files, and stores it internally. |
private
|
#
_setServerRequestParsed( string $parsed )
Creates an object that represents the parsed values, and stores it internally. |
private
|
#
_setServerRequestAttributes( string $attributes )
Creates an object that represents the attributes, and stores it internally. |
private
resource
|
#
_getServerRequestBodyValue( )
Provides a value to satisfy the underlying stream body value, based on the server request values. |
private
array
|
#
_getServerRequestHeadersValue( )
Provides a value to satisfy the underlying message headers value, based on the server request values. |
private
string
|
#
_getServerRequestProtocolValue( )
Provides a value to satisfy the underlying message protocol value, based on the server request values. |
private
string
|
#
_getServerRequestHostValue( )
Provides a value to satisfy the underlying request host value, based on the server request values. |
private
string
|
#
_getServerRequestUriValue( )
Provides a value to satisfy the underlying request uri value, based on the server request values. |
private
string
|
#
_getServerRequestMethodValue( )
Provides a value to satisfy the underlying request method value, based on the server request values. |
private
array
|
#
_getMessageValues( )
Returns the current internal values, for instantiation of new object instances while rendering the current object immutable. |
private
|
#
_instantiateMessageNewInstance( array $params = null )
Creates a new instance based off of the default parameters, substituting any values passed in. |
Methods used from oroboros\core\traits\libraries\request\RequestTrait
_getRequestDefaultHostname()
,
_getRequestDefaultRequestMethod()
,
_getRequestDefaultUri()
,
_initializeRequest()
,
_setRequestHostHeader()
,
_setRequestMethod()
,
_setRequestUri()
,
_validateRequestHost()
,
_validateRequestMethod()
,
_validateRequestUri()
,
getMethod()
,
getRequestTarget()
,
getUri()
,
withMethod()
,
withRequestTarget()
,
withUri()
Properties summary
private
array
|
$_server_request_params
Represents the server request parameters |
#
array()
|
private
array
|
$_server_request_cookies
Represents the server request cookies. |
#
array()
|
private
array
|
$_server_request_query
Represents the server request query |
#
array()
|
private
array
|
$_server_request_files
Represents the server request uploaded files |
#
array()
|
private
array
|
$_server_request_parsed
Represents the server request parsed body (POST) content |
#
array()
|
private
array
|
$_server_request_attributes
Represents the server request attributes |
#
array()
|
private
boolean
|
$_server_request_is_initialized
Represents whether the server request has been correctly initialized. |
#
false
|