PHP Class Webiny\Component\Http\Request

Inheritance: use trait Webiny\Component\StdLib\SingletonTrait, use trait Webiny\Component\StdLib\StdLibTrait
Show file Open project: Webiny/Framework Class Usage Examples

Public Methods

Method Description
env ( string $key = null, mixed $value = null ) : mixed Get a value from $_ENV param for the given $key.
files ( string $name, null | integer $arrayOffset = null ) : File Get the File object for the given $name.
getClientIp ( ) : string Get client ip address.
getConnectionPort ( ) : integer Return the connection port number.
getCurrentUrl ( boolean $asUrlObject = false ) : string | UrlObject Get current url with schema, host, port, request uri and query string.
getHostName ( ) : string Returns the host name.
getPayload ( ) : Payload Returns an array object with all post parameters.
getPost ( ) : Post Returns an array object with all POST parameters.
getQuery ( ) : Query Returns an array object with all GET parameters.
getRequestMethod ( ) : string Get request method from HTTP headers
getTrustedHeaders ( ) : array Get a list of trusted headers.
getTrustedProxies ( ) : array Array of IPs from trusted proxies.
header ( string $key = null, mixed $value = null ) : mixed Get a value from HTTP Headers If key doesn't not exist, $value will be returned and assigned under that key.
isDelete ( ) : boolean Checks if current request method is DELETE.
isGet ( ) : boolean Checks if current request method is GET.
isPatch ( ) : boolean Checks if current request method is PATCH.
isPost ( ) : boolean Checks if current request method is POST.
isPut ( ) : boolean Checks if current request method is PUT.
isRequestSecured ( ) : boolean Check if connection is secured.
payload ( string $key = null, mixed $value = null ) : mixed Get a value from request payload param for the given $key.
post ( string $key = null, mixed $value = null ) : mixed Get a value from $_POST param for the given $key.
query ( string $key = null, mixed $value = null ) : mixed Get a value from $_GET param for the given $key.
server ( ) : Server Access to the $_SERVER parameter over a object wrapper.
setCurrentUrl ( string $url ) This method sets the internal value of currentUrl to $url.
setRequestMethod ( string $requestMethod ) Set the request method.

Protected Methods

Method Description
init ( ) This function prepare the Request and all of its sub-classes.

Method Details

env() public method

If key doesn't not exist, $value will be returned and assigned under that key.
public env ( string $key = null, mixed $value = null ) : mixed
$key string Key for which you wish to get the value.
$value mixed Default value that will be returned if $key doesn't exist.
return mixed Value of the given $key.

files() public method

If you have a multi-dimensional upload field name, than you should pass the optional $arrayOffset param to get the right File object.
public files ( string $name, null | integer $arrayOffset = null ) : File
$name string Name of the upload field.
$arrayOffset null | integer Optional array offset for multi-dimensional upload fields.
return Webiny\Component\Http\Request\Files\File

getClientIp() public method

This function check and validates headers from trusted proxies.
public getClientIp ( ) : string
return string Client IP address.

getConnectionPort() public method

This function check the forwarded headers from trusted proxies.
public getConnectionPort ( ) : integer
return integer Port number.

getCurrentUrl() public method

You can get the result in a form of a string or as a url standard object.
public getCurrentUrl ( boolean $asUrlObject = false ) : string | UrlObject
$asUrlObject boolean In which format you want to get the result, url standard object or a string.
return string | Webiny\Component\StdLib\StdObject\UrlObject\UrlObject Current url.

getHostName() public method

This function check the forwarded headers from trusted proxies.
public getHostName ( ) : string
return string Host name

getPayload() public method

Returns an array object with all post parameters.
public getPayload ( ) : Payload
return Webiny\Component\Http\Request\Payload

getPost() public method

Returns an array object with all POST parameters.
public getPost ( ) : Post
return Webiny\Component\Http\Request\Post

getQuery() public method

Returns an array object with all GET parameters.
public getQuery ( ) : Query
return Webiny\Component\Http\Request\Query

getRequestMethod() public method

Get request method from HTTP headers
public getRequestMethod ( ) : string
return string

getTrustedHeaders() public method

Get a list of trusted headers.
public getTrustedHeaders ( ) : array
return array List of trusted headers.

getTrustedProxies() public method

Array of IPs from trusted proxies.
public getTrustedProxies ( ) : array
return array

header() public method

Get a value from HTTP Headers If key doesn't not exist, $value will be returned and assigned under that key.
public header ( string $key = null, mixed $value = null ) : mixed
$key string Key for which you wish to get the value.
$value mixed Default value that will be returned if $key doesn't exist.
return mixed Value of the given $key.

init() protected method

This class is called automatically by SingletonTrait.
protected init ( )

isDelete() public method

Checks if current request method is DELETE.
public isDelete ( ) : boolean
return boolean True if it's DELETE.

isGet() public method

Checks if current request method is GET.
public isGet ( ) : boolean
return boolean True if it's GET.

isPatch() public method

Checks if current request method is PATCH.
public isPatch ( ) : boolean
return boolean True if it's PATCH.

isPost() public method

Checks if current request method is POST.
public isPost ( ) : boolean
return boolean True if it's POST.

isPut() public method

Checks if current request method is PUT.
public isPut ( ) : boolean
return boolean True if it's PUT.

isRequestSecured() public method

This function check the forwarded headers from trusted proxies.
public isRequestSecured ( ) : boolean
return boolean True if connection is secured (https), otherwise false is returned.

payload() public method

If key doesn't not exist, $value will be returned and assigned under that key.
public payload ( string $key = null, mixed $value = null ) : mixed
$key string Key for which you wish to get the value.
$value mixed Default value that will be returned if $key doesn't exist.
return mixed Value of the given $key.

post() public method

If key doesn't not exist, $value will be returned and assigned under that key.
public post ( string $key = null, mixed $value = null ) : mixed
$key string Key for which you wish to get the value.
$value mixed Default value that will be returned if $key doesn't exist.
return mixed Value of the given $key.

query() public method

If key doesn't not exist, $value will be returned and assigned under that key.
public query ( string $key = null, mixed $value = null ) : mixed
$key string Key for which you wish to get the value.
$value mixed Default value that will be returned if $key doesn't exist.
return mixed Value of the given $key.

server() public method

Access to the $_SERVER parameter over a object wrapper.
public server ( ) : Server
return Webiny\Component\Http\Request\Server

setCurrentUrl() public method

This method will not actually do a redirect, it is used mostly for mocking the internal value.
public setCurrentUrl ( string $url )
$url string Current url.

setRequestMethod() public method

Set the request method.
public setRequestMethod ( string $requestMethod )
$requestMethod string Request method name. Example 'GET', 'POST' ...