Request
Request
Properties
method
public string $method
context
public mixed $context
rawURL
public string $rawURL
headers
private $headers
url
private URL $url
fsock_host
private string $fsock_host
body
private mixed $body
multipart
private bool $multipart
dontEncodeURL
private bool $dontEncodeURL
jsonEncodeFlags
private int $jsonEncodeFlags
jsonEncodeDepth
private int $jsonEncodeDepth
Methods
__construct
HTTP request constructor.
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$url | URL | The url of the resource that will be requested |
$method | string | The request method to use. Typically GET, POST, etc |
$content_type | string | optionally set the content type header |
$custom_context | mixed | Optionally use a custom context. Allows to define private SSL certificates. |
url
Set the url of the resource that is being requested.
public url({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$url | URL |
setContentType
Sets the Content-Type header for the request.
public setContentType({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$content_type | string |
getContentType
Returns the current Content-Type header for the request.
public getContentType({Array})
enableMultipart
Enable multipart mime request body optionally using the specified boundary and content type.
public enableMultipart({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$content_type | string | Optional request content type to use. Defaults to multipart/form-data. |
$boundary | string | Optional boundary identifier. Defaults to HazaarMVCMultipartBoundary_{uniqid} |
isMultipart
Returns a boolean indicating if the request is a multipart request.
public isMultipart({Array})
getMultipartBoundary
Return the current multipart boundary name.
public getMultipartBoundary({Array})
addMultipart
Add a multipart chunk to the request.
public addMultipart({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$data | mixed | the data to add to the request |
$content_type | string | the content type of the added data |
$headers | array |
getHost
Returns the name of the host that will be sent this request.
public getHost({Array})
setBody
Set the request body.
public setBody({Array})
If multipart is enabled, then the body will be added as a new chunk.
Parameters
Parameter | Type | Description |
---|---|---|
$body | mixed | |
$content_type | string |
getBody
Return the body of the request.
public getBody({Array})
If multipart is enabled, this will return an array containing request body and content type.
getHeaders
Returns all the headers currently set on the request.
public getHeaders({Array})
getHeader
Returns the value of the header specified by $key.
public getHeader({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | The name of the header to return |
setHeader
Sets the value of a header.
public setHeader({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the name of the header to set |
$value | string | the value to set on the header |
$allow_multiple | bool | Whether multiple instances of the header are allowed. Defaults to false, meaning if the |
header exists, it will be updated. Multiple headers are rare but the main one is 'Cookie'. |
toString
Output the request as a string.
public toString({Array})
This is the method that renders the request as a HTTP/1.1 compliant request.
Parameters
Parameter | Type | Description |
---|---|---|
$encryption_key | string | optionally encrypt the request using this encryption key |
$encryption_cipher | string | optionally specifiy the cipher used to encrypt the request |
authorise
Add Basic HTTP authentication.
public authorise({Array})
Basic authentication should ONLY be used over HTTPS.
Other methods are not yet supported, however Bearer is implemented using Request::authorization() method.
Parameters
Parameter | Type | Description |
---|---|---|
$username | string | The username to send |
$password | string | The password to send |
authorization
Alias for 'authorisation' for the bad 'merican spells.
public authorization({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$user | Adapter | |
$type | string |
authorisation
Use an auth adapter to set an Oauth token on the request.
public authorisation({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$user | Adapter | |
$type | string |
setLocalCertificate
Set a local PEM encoded certificate to use for SSL communication.
public setLocalCertificate({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$local_cert | string | |
$passphrase | string | |
$local_pk | string |
setContextOption
Wrapper function to the internal PHP function stream_context_set_option() function.
public setContextOption({Array})
See http://php.net/manual/en/context.ssl.php documentation for all the available wrappers and options.
Parameters
Parameter | Type | Description |
---|---|---|
$options | array | Must be an associative array in the format $arr['wrapper']['option'] = $value; |
allowSelfSigned
When using SSL communications, this allows the use of self-signed certificates.
public allowSelfSigned({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$value | bool |
verifyPeer
When using SSL communications, this sets whether peer certificate verification is used.
public verifyPeer({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$value | bool |
verifyPeerName
When using SSL communications, this sets whether peer name verification is used.
public verifyPeerName({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$value | bool |
setURLEncode
Enable/Disable URL encoding.
public setURLEncode({Array})
url encoding is enabled by default. Internally this calls PHPs rawurlencode() function to encode URLs into HTTP safe urls. However there may occasionally be special circumstances where the encoding may need to be disabled. Usually this is becuase the encoding is already being done by the calling function/class.
A prime example of this is Hazaar MVC's SharePoint filesystem backend driver. SharePoint is very finicky about the format of the urls and wants some characters left alone (ie: brackets and quotes) as they make up the function/path reference being accessed. These functions/references will then have their contents only encoded and this is handled by the driver itself so encoding again in the Request
class will screw things up.
Parameters
Parameter | Type | Description |
---|---|---|
$value | bool | TRUE enables encoding (the default). FALSE will disable encoding. |
setJSONEncodeFlags
Set JSON encoding flags/depth used when request is encoded to JSON.
public setJSONEncodeFlags({Array})
Requests will automatically encode any data parameters to JSON encoded strings when generating the reqeust as a string. If there are any JSON encoding flags required, this function will apply those flags to all JSON encoding methods used when rendering the request. This includes requests sent with a mime content type of application/json
as well as multipart encoded requests.
Parameters
Parameter | Type | Description |
---|---|---|
$flags | int | |
$depth | int |
Generated by Hazaar API Doc Generator