Request
extends AbstractRequest
in package
HTTP client request class
Tags
Table of Contents
Constants
- JSON = 'application/json'
- MULTIPART = 'multipart/form-data'
- URLENCODED = 'application/x-www-form-urlencoded'
- Request type constants
- XML = 'application/xml'
Properties
- $body : Body|null
- Body
- $data : Data|null
- Client request data object
- $headers : array<string|int, mixed>
- Headers
- $method : string|null
- Request method
- $query : Data|null
- Client request query data object
- $requestType : string|null
- Request type
- $uri : Uri|null
- Request URI object
Methods
- __call() : bool
- Magic method to check the is[Method](), i.e. $request->isPost();
- __construct() : mixed
- Constructor
- __get() : mixed
- Magic method to get either the headers or body
- addData() : Request
- Add data
- addHeader() : Request
- Add a header
- addHeaders() : AbstractRequestResponse
- Add all headers
- addQuery() : Request
- Add query data
- create() : Request
- Factory method to create a Request object
- createAsCustomType() : Request
- Create request as custom content type
- createAsJson() : Request
- Create request as JSON
- createAsMultipart() : Request
- Create request as a multipart form
- createAsUrlEncoded() : Request
- Create request as a URL-encoded form
- createAsXml() : Request
- Create request as XML
- createJson() : Request
- Factory method to create a JSON Request object
- createMultipart() : Request
- Factory method to create a multipart Request object
- createUrlEncoded() : Request
- Factory method to create a URL-encoded Request object
- createXml() : Request
- Factory method to create an XML Request object
- decodeBodyContent() : Body
- Decode the body
- getBody() : Body
- Get the body
- getBodyContent() : mixed
- Get body content
- getBodyContentLength() : int
- Get body content length
- getData() : Data|null
- Get data
- getDataContent() : string|null
- Get the data content
- getDataContentLength() : int|null
- Get the data content length
- getHeader() : mixed
- Get a header
- getHeaderAsString() : mixed
- Get a header
- getHeaders() : array<string|int, mixed>
- Get all headers
- getHeadersAsArray() : array<string|int, mixed>
- Get all header values as associative array
- getHeadersAsString() : string
- Get all header values formatted string
- getHeaderValue() : mixed
- Get header value
- getHeaderValueAsString() : string|null
- Get header value as string
- getMethod() : string|null
- Get method
- getQuery() : Data|null
- Get query data
- getRequestType() : string|null
- Get request type
- getUri() : Uri
- Get URI
- getUriAsString() : string
- Get full URI as string
- hasBody() : bool
- Has a body
- hasBodyContent() : bool
- Has body content
- hasData() : bool
- Has data
- hasDataContent() : bool
- Has data content
- hasHeader() : bool
- Has a header
- hasHeaders() : bool
- Determine if there are headers
- hasMethod() : bool
- Has method
- hasQuery() : bool
- Has query data
- hasRequestType() : bool
- Has request type
- hasUri() : bool
- Has URI
- isCustomType() : bool
- Check if request is a custom content type
- isJson() : bool
- Check if request is JSON
- isMultipart() : bool
- Check if request is a multipart form
- isUrlEncoded() : bool
- Check if request is a URL-encoded form
- isValidMethod() : bool
- Is valid method
- isXml() : bool
- Check if request is XML
- prepareData() : Request
- Prepare request data
- removeAllData() : Request
- Remove all data
- removeAllQuery() : Request
- Remove all query data
- removeBody() : AbstractRequestResponse
- Remove the body
- removeData() : Request
- Remove data
- removeHeader() : AbstractRequestResponse
- Remove a header
- removeHeaders() : AbstractRequestResponse
- Remove all headers
- removeQuery() : Request
- Remove query data
- removeRequestType() : Request
- Remove request type
- setBody() : AbstractRequestResponse
- Set the body
- setData() : Request
- Set data
- setHeaders() : AbstractRequestResponse
- Set all headers (clear out any existing headers)
- setMethod() : Request
- Set method
- setQuery() : Request
- Set query data
- setRequestType() : Request
- Set request type
- setUri() : AbstractRequest
- Set URI
Constants
JSON
public
mixed
JSON
= 'application/json'
MULTIPART
public
mixed
MULTIPART
= 'multipart/form-data'
URLENCODED
Request type constants
public
string
URLENCODED
= 'application/x-www-form-urlencoded'
XML
public
mixed
XML
= 'application/xml'
Properties
$body
Body
protected
Body|null
$body
= null
$data
Client request data object
protected
Data|null
$data
= null
Can be any type of supported request data:
- URL-encoded query string on the URI (GET method)
- URL-encoded body (any method other than GET)
- JSON-encoded body
- XML-encoded body
- Multipart/form body
$headers
Headers
protected
array<string|int, mixed>
$headers
= []
$method
Request method
protected
string|null
$method
= null
$query
Client request query data object
protected
Data|null
$query
= null
Can only be a URL-encoded query string on the URI
$requestType
Request type
protected
string|null
$requestType
= null
$uri
Request URI object
protected
Uri|null
$uri
= null
Methods
__call()
Magic method to check the is[Method](), i.e. $request->isPost();
public
__call(string $methodName[, array<string|int, mixed>|null $arguments = null ]) : bool
Parameters
- $methodName : string
- $arguments : array<string|int, mixed>|null = null
Tags
Return values
bool__construct()
Constructor
public
__construct([Uri|string|null $uri = null ][, string $method = 'GET' ][, mixed $data = null ][, string|null $type = null ][, bool $strict = false ]) : mixed
Instantiate the request data object
Parameters
- $uri : Uri|string|null = null
- $method : string = 'GET'
- $data : mixed = null
- $type : string|null = null
- $strict : bool = false
Tags
__get()
Magic method to get either the headers or body
public
__get(string $name) : mixed
Parameters
- $name : string
addData()
Add data
public
addData(mixed $name, mixed $value) : Request
Parameters
- $name : mixed
- $value : mixed
Return values
RequestaddHeader()
Add a header
public
addHeader(Header|string|int $header[, string|null $value = null ]) : Request
Parameters
- $header : Header|string|int
- $value : string|null = null
Return values
RequestaddHeaders()
Add all headers
public
addHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponseaddQuery()
Add query data
public
addQuery(mixed $name, mixed $value) : Request
Parameters
- $name : mixed
- $value : mixed
Return values
Requestcreate()
Factory method to create a Request object
public
static create([Uri|string|null $uri = null ][, string $method = 'GET' ][, mixed $data = null ][, string|null $type = null ][, bool $strict = false ]) : Request
Parameters
- $uri : Uri|string|null = null
- $method : string = 'GET'
- $data : mixed = null
- $type : string|null = null
- $strict : bool = false
Tags
Return values
RequestcreateAsCustomType()
Create request as custom content type
public
createAsCustomType(string $type[, bool $addHeader = true ]) : Request
Parameters
- $type : string
- $addHeader : bool = true
Return values
RequestcreateAsJson()
Create request as JSON
public
createAsJson([string $type = self::JSON ][, bool $addHeader = true ]) : Request
Parameters
- $type : string = self::JSON
- $addHeader : bool = true
Return values
RequestcreateAsMultipart()
Create request as a multipart form
public
createAsMultipart([string $type = self::MULTIPART ]) : Request
Parameters
- $type : string = self::MULTIPART
Return values
RequestcreateAsUrlEncoded()
Create request as a URL-encoded form
public
createAsUrlEncoded([string $type = self::URLENCODED ][, bool $addHeader = true ]) : Request
Parameters
- $type : string = self::URLENCODED
- $addHeader : bool = true
Return values
RequestcreateAsXml()
Create request as XML
public
createAsXml([string $type = self::XML ][, bool $addHeader = true ]) : Request
Parameters
- $type : string = self::XML
- $addHeader : bool = true
Return values
RequestcreateJson()
Factory method to create a JSON Request object
public
static createJson([Uri|string|null $uri = null ][, string $method = 'POST' ][, mixed $data = null ][, bool $strict = false ]) : Request
Parameters
- $uri : Uri|string|null = null
- $method : string = 'POST'
- $data : mixed = null
- $strict : bool = false
Tags
Return values
RequestcreateMultipart()
Factory method to create a multipart Request object
public
static createMultipart([Uri|string|null $uri = null ][, string $method = 'POST' ][, mixed $data = null ][, bool $strict = false ]) : Request
Parameters
- $uri : Uri|string|null = null
- $method : string = 'POST'
- $data : mixed = null
- $strict : bool = false
Tags
Return values
RequestcreateUrlEncoded()
Factory method to create a URL-encoded Request object
public
static createUrlEncoded([Uri|string|null $uri = null ][, string $method = 'GET' ][, mixed $data = null ][, bool $strict = false ]) : Request
Parameters
- $uri : Uri|string|null = null
- $method : string = 'GET'
- $data : mixed = null
- $strict : bool = false
Tags
Return values
RequestcreateXml()
Factory method to create an XML Request object
public
static createXml([Uri|string|null $uri = null ][, string $method = 'POST' ][, mixed $data = null ][, bool $strict = false ]) : Request
Parameters
- $uri : Uri|string|null = null
- $method : string = 'POST'
- $data : mixed = null
- $strict : bool = false
Tags
Return values
RequestdecodeBodyContent()
Decode the body
public
decodeBodyContent([string|null $body = null ]) : Body
Parameters
- $body : string|null = null
Return values
BodygetBody()
Get the body
public
getBody() : Body
Return values
BodygetBodyContent()
Get body content
public
getBodyContent() : mixed
getBodyContentLength()
Get body content length
public
getBodyContentLength([bool $mb = false ]) : int
Parameters
- $mb : bool = false
Return values
intgetData()
Get data
public
getData() : Data|null
Return values
Data|nullgetDataContent()
Get the data content
public
getDataContent() : string|null
Return values
string|nullgetDataContentLength()
Get the data content length
public
getDataContentLength([bool $mb = false ]) : int|null
Parameters
- $mb : bool = false
Return values
int|nullgetHeader()
Get a header
public
getHeader(string $name) : mixed
Parameters
- $name : string
getHeaderAsString()
Get a header
public
getHeaderAsString(string $name) : mixed
Parameters
- $name : string
getHeaders()
Get all headers
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeadersAsArray()
Get all header values as associative array
public
getHeadersAsArray([bool $asStrings = true ]) : array<string|int, mixed>
Parameters
- $asStrings : bool = true
Return values
array<string|int, mixed>getHeadersAsString()
Get all header values formatted string
public
getHeadersAsString([mixed $status = null ][, string $eol = "
" ]) : string
Parameters
- $status : mixed = null
- $eol : string = " "
Return values
stringgetHeaderValue()
Get header value
public
getHeaderValue(string $name[, int $i = 0 ]) : mixed
Parameters
- $name : string
- $i : int = 0
getHeaderValueAsString()
Get header value as string
public
getHeaderValueAsString(string $name[, int $i = 0 ]) : string|null
Parameters
- $name : string
- $i : int = 0
Return values
string|nullgetMethod()
Get method
public
getMethod() : string|null
Return values
string|nullgetQuery()
Get query data
public
getQuery() : Data|null
Return values
Data|nullgetRequestType()
Get request type
public
getRequestType() : string|null
Return values
string|nullgetUri()
Get URI
public
getUri() : Uri
Return values
UrigetUriAsString()
Get full URI as string
public
getUriAsString([bool $query = true ]) : string
Parameters
- $query : bool = true
Return values
stringhasBody()
Has a body
public
hasBody() : bool
Return values
boolhasBodyContent()
Has body content
public
hasBodyContent() : bool
Return values
boolhasData()
Has data
public
hasData() : bool
Return values
boolhasDataContent()
Has data content
public
hasDataContent() : bool
Return values
boolhasHeader()
Has a header
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolhasHeaders()
Determine if there are headers
public
hasHeaders() : bool
Return values
boolhasMethod()
Has method
public
hasMethod() : bool
Return values
boolhasQuery()
Has query data
public
hasQuery() : bool
Return values
boolhasRequestType()
Has request type
public
hasRequestType() : bool
Return values
boolhasUri()
Has URI
public
hasUri() : bool
Return values
boolisCustomType()
Check if request is a custom content type
public
isCustomType() : bool
Return values
boolisJson()
Check if request is JSON
public
isJson() : bool
Return values
boolisMultipart()
Check if request is a multipart form
public
isMultipart() : bool
Return values
boolisUrlEncoded()
Check if request is a URL-encoded form
public
isUrlEncoded() : bool
Return values
boolisValidMethod()
Is valid method
public
isValidMethod(string $method) : bool
Parameters
- $method : string
Return values
boolisXml()
Check if request is XML
public
isXml() : bool
Return values
boolprepareData()
Prepare request data
public
prepareData() : Request
Return values
RequestremoveAllData()
Remove all data
public
removeAllData() : Request
Return values
RequestremoveAllQuery()
Remove all query data
public
removeAllQuery() : Request
Return values
RequestremoveBody()
Remove the body
public
removeBody() : AbstractRequestResponse
Return values
AbstractRequestResponseremoveData()
Remove data
public
removeData(string $key) : Request
Parameters
- $key : string
Return values
RequestremoveHeader()
Remove a header
public
removeHeader(string $name) : AbstractRequestResponse
Parameters
- $name : string
Return values
AbstractRequestResponseremoveHeaders()
Remove all headers
public
removeHeaders() : AbstractRequestResponse
Return values
AbstractRequestResponseremoveQuery()
Remove query data
public
removeQuery(string $key) : Request
Parameters
- $key : string
Return values
RequestremoveRequestType()
Remove request type
public
removeRequestType([bool $removeHeader = false ]) : Request
Parameters
- $removeHeader : bool = false
Return values
RequestsetBody()
Set the body
public
setBody(string|Body $body) : AbstractRequestResponse
Parameters
- $body : string|Body
Return values
AbstractRequestResponsesetData()
Set data
public
setData(mixed $data[, mixed $filters = null ]) : Request
Parameters
- $data : mixed
- $filters : mixed = null
Return values
RequestsetHeaders()
Set all headers (clear out any existing headers)
public
setHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponsesetMethod()
Set method
public
setMethod(string $method[, bool $strict = false ]) : Request
Parameters
- $method : string
- $strict : bool = false
Tags
Return values
RequestsetQuery()
Set query data
public
setQuery(mixed $query[, mixed $filters = null ]) : Request
Parameters
- $query : mixed
- $filters : mixed = null
Return values
RequestsetRequestType()
Set request type
public
setRequestType([string|null $type = null ][, bool $handleHeader = true ]) : Request
Parameters
- $type : string|null = null
- $handleHeader : bool = true
Return values
RequestsetUri()
Set URI
public
setUri(Uri|string $uri) : AbstractRequest
Parameters
- $uri : Uri|string