Documentation

Request extends AbstractRequest
in package

HTTP client request class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
5.2.0

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
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
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

$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

$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

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
throws
Exception
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
throws
Exception|Exception

__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
Request

addHeader()

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
Request

addQuery()

Add query data

public addQuery(mixed $name, mixed $value) : Request
Parameters
$name : mixed
$value : mixed
Return values
Request

create()

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
throws
Exception|Exception
Return values
Request

createAsMultipart()

Create request as a multipart form

public createAsMultipart() : Request
Return values
Request

createAsUrlEncoded()

Create request as a URL-encoded form

public createAsUrlEncoded() : Request
Return values
Request

createJson()

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
throws
Exception|Exception
Return values
Request

createMultipart()

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
throws
Exception|Exception
Return values
Request

createUrlEncoded()

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
throws
Exception|Exception
Return values
Request

createXml()

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
throws
Exception|Exception
Return values
Request

decodeBodyContent()

Decode the body

public decodeBodyContent([string|null $body = null ]) : Body
Parameters
$body : string|null = null
Return values
Body

getBodyContentLength()

Get body content length

public getBodyContentLength([bool $mb = false ]) : int
Parameters
$mb : bool = false
Return values
int

getDataContent()

Get the data content

public getDataContent() : string|null
Return values
string|null

getDataContentLength()

Get the data content length

public getDataContentLength([bool $mb = false ]) : int|null
Parameters
$mb : bool = false
Return values
int|null

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
string

getHeaderValue()

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|null

getMethod()

Get method

public getMethod() : string|null
Return values
string|null

getQuery()

Get query data

public getQuery() : Data|null
Return values
Data|null

getRequestType()

Get request type

public getRequestType() : string|null
Return values
string|null

getUriAsString()

Get full URI as string

public getUriAsString([bool $query = true ]) : string
Parameters
$query : bool = true
Return values
string

hasData()

Has data

public hasData() : bool
Return values
bool

hasDataContent()

Has data content

public hasDataContent() : bool
Return values
bool

hasHeader()

Has a header

public hasHeader(string $name) : bool
Parameters
$name : string
Return values
bool

hasMethod()

Has method

public hasMethod() : bool
Return values
bool

hasQuery()

Has query data

public hasQuery() : bool
Return values
bool

hasRequestType()

Has request type

public hasRequestType() : bool
Return values
bool

isJson()

Check if request is JSON

public isJson() : bool
Return values
bool

isMultipart()

Check if request is a multipart form

public isMultipart() : bool
Return values
bool

isUrlEncoded()

Check if request is a URL-encoded form

public isUrlEncoded() : bool
Return values
bool

isValidMethod()

Is valid method

public isValidMethod(string $method) : bool
Parameters
$method : string
Return values
bool

isXml()

Check if request is XML

public isXml() : bool
Return values
bool

removeData()

Remove data

public removeData(string $key) : Request
Parameters
$key : string
Return values
Request

removeQuery()

Remove query data

public removeQuery(string $key) : Request
Parameters
$key : string
Return values
Request

setData()

Set data

public setData(mixed $data[, mixed $filters = null ]) : Request
Parameters
$data : mixed
$filters : mixed = null
Return values
Request

setMethod()

Set method

public setMethod(string $method[, bool $strict = false ]) : Request
Parameters
$method : string
$strict : bool = false
Tags
throws
Exception
Return values
Request

setQuery()

Set query data

public setQuery(mixed $query[, mixed $filters = null ]) : Request
Parameters
$query : mixed
$filters : mixed = null
Return values
Request

setRequestType()

Set request type

public setRequestType([string|null $type = null ]) : Request
Parameters
$type : string|null = null
Return values
Request

        
On this page

Search results