HumHub Documentation (unofficial)

Client
in package
implements DispatchableInterface

Http client

Table of Contents

Interfaces

DispatchableInterface

Constants

AUTH_BASIC  = 'basic'
AUTH_DIGEST  = 'digest'
DIGEST_CNONCE  = 'cnonce'
DIGEST_NC  = 'nc'
DIGEST_NONCE  = 'nonce'
DIGEST_OPAQUE  = 'opaque'
DIGEST_QOP  = 'qop'
DIGEST_REALM  = 'realm'
ENC_FORMDATA  = 'multipart/form-data'
ENC_URLENCODED  = 'application/x-www-form-urlencoded'

Properties

$adapter  : AdapterInterface
$auth  : array<string|int, mixed>
$config  : array<string|int, mixed>
Configuration array, set using the constructor or using ::setOptions()
$cookies  : array<string|int, mixed>
$encType  : string
$fileInfoDb  : resource
Fileinfo magic database resource
$lastRawRequest  : Request
$lastRawResponse  : Response
$redirectCounter  : int
$request  : Request
$response  : Response
$streamHandle  : resource|null
$streamName  : string

Methods

__construct()  : mixed
Constructor
addCookie()  : $this
Add a cookie
clearAuth()  : mixed
Clear http authentication
clearCookies()  : mixed
Clear all the cookies
dispatch()  : ResponseInterface
Dispatch
encodeAuthHeader()  : string
Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.
encodeFormData()  : string
Encode data to a multipart/form-data part suitable for a POST request.
getAdapter()  : AdapterInterface
Load the connection adapter
getArgSeparator()  : string
Get the query string argument separator
getCookies()  : array<string|int, mixed>
Return the current cookies
getEncType()  : string
Get the encoding type
getHeader()  : string|bool
Get the header value of the request
getLastRawRequest()  : string
Get the last request (as a string)
getLastRawResponse()  : string
Get the last response (as a string)
getMethod()  : string
Get the HTTP method
getRedirectionsCount()  : int
Get the redirections count
getRequest()  : Request
Get Request
getResponse()  : Response
Get Response
getStream()  : bool|string
Get status of streaming for received data
getUri()  : Http
Get uri (from the request)
hasHeader()  : bool
Check if exists the header type specified
removeFileUpload()  : bool
Remove a file to upload
reset()  : $this
Fully reset the HTTP client (auth, cookies, request, response, etc.)
resetParameters()  : $this
Reset all the HTTP parameters (request, response, etc)
send()  : Response
Send HTTP request
setAdapter()  : $this
Load the connection adapter
setArgSeparator()  : $this
Set the query string argument separator
setAuth()  : $this
Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.
setCookies()  : $this
Set an array of cookies
setEncType()  : $this
Set the encoding type and the boundary (if any)
setFileUpload()  : $this
Set a file to upload (using a POST request)
setHeaders()  : $this
Set the headers (for the request)
setMethod()  : $this
Set the HTTP method (to the request)
setOptions()  : $this
Set configuration parameters for this HTTP client
setParameterGet()  : $this
Set the GET parameters
setParameterPost()  : $this
Set the POST parameters
setRawBody()  : $this
Set raw body (for advanced use cases)
setRequest()  : $this
Set request
setResponse()  : $this
Set response
setStream()  : $this
Set streaming for received data
setUri()  : $this
Set Uri (to the request)
calcAuthDigest()  : string|bool
Calculate the response value according to the HTTP authentication type
detectFileMimeType()  : string
Attempt to detect the MIME type of a file using available extensions
doRequest()  : string
Separating this from send method allows subclasses to wrap the interaction with the adapter
flattenParametersArray()  : array<string|int, mixed>
Convert an array of parameters into a flat array of (key, value) pairs
getCookieId()  : string|bool
Get the cookie Id (name+domain+path)
openTempStream()  : resource
Create temporary stream
prepareBody()  : string
Prepare the request body (for PATCH, POST and PUT requests)
prepareCookies()  : Cookie|bool
Prepare Cookies
prepareHeaders()  : array<string|int, mixed>
Prepare the request headers

Constants

AUTH_BASIC

public mixed AUTH_BASIC = 'basic'
Tags
const

string Supported HTTP Authentication methods

AUTH_DIGEST

public mixed AUTH_DIGEST = 'digest'

DIGEST_CNONCE

public mixed DIGEST_CNONCE = 'cnonce'

DIGEST_NC

public mixed DIGEST_NC = 'nc'

DIGEST_NONCE

public mixed DIGEST_NONCE = 'nonce'

DIGEST_OPAQUE

public mixed DIGEST_OPAQUE = 'opaque'

DIGEST_QOP

public mixed DIGEST_QOP = 'qop'

DIGEST_REALM

public mixed DIGEST_REALM = 'realm'
Tags
const

string DIGEST Authentication

ENC_FORMDATA

public mixed ENC_FORMDATA = 'multipart/form-data'

ENC_URLENCODED

public mixed ENC_URLENCODED = 'application/x-www-form-urlencoded'
Tags
const

string POST data encoding methods

Properties

$auth

protected array<string|int, mixed> $auth = []

$config

Configuration array, set using the constructor or using ::setOptions()

protected array<string|int, mixed> $config = ['maxredirects' => 5, 'strictredirects' => false, 'useragent' => 'Laminas_Http_Client', 'timeout' => 10, 'connecttimeout' => null, 'adapter' => \Laminas\Http\Client\Adapter\Socket::class, 'httpversion' => \Laminas\Http\Request::VERSION_11, 'storeresponse' => true, 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, 'argseparator' => null, 'rfc3986strict' => false, 'sslcafile' => null, 'sslcapath' => null]

$cookies

protected array<string|int, mixed> $cookies = []

of Header\SetCookie

$encType

protected string $encType = ''

$fileInfoDb

Fileinfo magic database resource

protected static resource $fileInfoDb

This variable is populated the first time _detectFileMimeType is called and is then reused on every call to this method

$redirectCounter

protected int $redirectCounter = 0

$streamHandle

protected resource|null $streamHandle

$streamName

protected string $streamName

Methods

__construct()

Constructor

public __construct([string $uri = null ][, array<string|int, mixed>|Traversable $options = null ]) : mixed
Parameters
$uri : string = null
$options : array<string|int, mixed>|Traversable = null

addCookie()

Add a cookie

public addCookie(array<string|int, mixed>|ArrayIterator|SetCookie|string $cookie[, string $value = null ][, string $expire = null ][, string $path = null ][, string $domain = null ][, bool $secure = false ][, bool $httponly = true ][, string $maxAge = null ][, string $version = null ]) : $this
Parameters
$cookie : array<string|int, mixed>|ArrayIterator|SetCookie|string
$value : string = null
$expire : string = null
$path : string = null
$domain : string = null
$secure : bool = false
$httponly : bool = true
$maxAge : string = null
$version : string = null
Tags
throws
InvalidArgumentException
Return values
$this

clearAuth()

Clear http authentication

public clearAuth() : mixed

clearCookies()

Clear all the cookies

public clearCookies() : mixed

encodeAuthHeader()

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

public static encodeAuthHeader(string $user, string $password[, string $type = self::AUTH_BASIC ]) : string
Parameters
$user : string
$password : string
$type : string = self::AUTH_BASIC
Tags
see
http://www.faqs.org/rfcs/rfc2617.html
throws
InvalidArgumentException
Return values
string

encodeFormData()

Encode data to a multipart/form-data part suitable for a POST request.

public encodeFormData(string $boundary, string $name, mixed $value[, string $filename = null ][, array<string|int, mixed> $headers = [] ]) : string
Parameters
$boundary : string
$name : string
$value : mixed
$filename : string = null
$headers : array<string|int, mixed> = []

Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")

Return values
string

getArgSeparator()

Get the query string argument separator

public getArgSeparator() : string
Return values
string

getCookies()

Return the current cookies

public getCookies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getEncType()

Get the encoding type

public getEncType() : string
Return values
string

getHeader()

Get the header value of the request

public getHeader(string $name) : string|bool
Parameters
$name : string
Return values
string|bool

getLastRawRequest()

Get the last request (as a string)

public getLastRawRequest() : string
Return values
string

getLastRawResponse()

Get the last response (as a string)

public getLastRawResponse() : string
Return values
string

getMethod()

Get the HTTP method

public getMethod() : string
Return values
string

getRedirectionsCount()

Get the redirections count

public getRedirectionsCount() : int
Return values
int

getStream()

Get status of streaming for received data

public getStream() : bool|string
Return values
bool|string

getUri()

Get uri (from the request)

public getUri() : Http
Return values
Http

hasHeader()

Check if exists the header type specified

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

removeFileUpload()

Remove a file to upload

public removeFileUpload(string $filename) : bool
Parameters
$filename : string
Return values
bool

reset()

Fully reset the HTTP client (auth, cookies, request, response, etc.)

public reset() : $this
Return values
$this

resetParameters()

Reset all the HTTP parameters (request, response, etc)

public resetParameters([bool $clearCookies = false ]) : $this
Parameters
$clearCookies : bool = false

Also clear all valid cookies? (defaults to false)

Return values
$this

setAdapter()

Load the connection adapter

public setAdapter(AdapterInterface|string $adapter) : $this

While this method is not called more than one for a client, it is separated from ->request() to preserve logic and readability

Parameters
$adapter : AdapterInterface|string
Tags
throws
InvalidArgumentException
Return values
$this

setArgSeparator()

Set the query string argument separator

public setArgSeparator(string $argSeparator) : $this
Parameters
$argSeparator : string
Return values
$this

setAuth()

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

public setAuth(string $user, string $password[, string $type = self::AUTH_BASIC ]) : $this
Parameters
$user : string
$password : string
$type : string = self::AUTH_BASIC
Tags
throws
InvalidArgumentException
Return values
$this

setCookies()

Set an array of cookies

public setCookies(array<string|int, mixed>|array<string|int, SetCookie$cookies) : $this
Parameters
$cookies : array<string|int, mixed>|array<string|int, SetCookie>

Cookies as name=>value pairs or instances of SetCookie.

Tags
throws
InvalidArgumentException
Return values
$this

setEncType()

Set the encoding type and the boundary (if any)

public setEncType(string $encType[, string $boundary = null ]) : $this
Parameters
$encType : string
$boundary : string = null
Return values
$this

setFileUpload()

Set a file to upload (using a POST request)

public setFileUpload(string $filename, string $formname[, string $data = null ][, string $ctype = null ]) : $this

Can be used in two ways:

  1. $data is null (default): $filename is treated as the name if a local file which will be read and sent. Will try to guess the content type using mime_content_type().
  2. $data is set - $filename is sent as the file name, but $data is sent as the file contents and no file is read from the file system. In this case, you need to manually set the Content-Type ($ctype) or it will default to application/octet-stream.
Parameters
$filename : string

Name of file to upload, or name to save as

$formname : string

Name of form element to send as

$data : string = null

Data to send (if null, $filename is read and sent)

$ctype : string = null

Content type to use (if $data is set and $ctype is null, will be application/octet-stream)

Tags
throws
RuntimeException
Return values
$this

setHeaders()

Set the headers (for the request)

public setHeaders(Headers|array<string|int, mixed> $headers) : $this
Parameters
$headers : Headers|array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
$this

setMethod()

Set the HTTP method (to the request)

public setMethod(string $method) : $this
Parameters
$method : string
Return values
$this

setOptions()

Set configuration parameters for this HTTP client

public setOptions([array<string|int, mixed>|Traversable $options = [] ]) : $this
Parameters
$options : array<string|int, mixed>|Traversable = []
Tags
throws
InvalidArgumentException
Return values
$this

setParameterGet()

Set the GET parameters

public setParameterGet(array<string|int, mixed> $query) : $this
Parameters
$query : array<string|int, mixed>
Return values
$this

setParameterPost()

Set the POST parameters

public setParameterPost(array<string|int, mixed> $post) : $this
Parameters
$post : array<string|int, mixed>
Return values
$this

setRawBody()

Set raw body (for advanced use cases)

public setRawBody(string $body) : $this
Parameters
$body : string
Return values
$this

setRequest()

Set request

public setRequest(Request $request) : $this
Parameters
$request : Request
Return values
$this

setResponse()

Set response

public setResponse(Response $response) : $this
Parameters
$response : Response
Return values
$this

setStream()

Set streaming for received data

public setStream([string|bool $streamfile = true ]) : $this
Parameters
$streamfile : string|bool = true

Stream file, true for temp file, false/null for no streaming

Return values
$this

setUri()

Set Uri (to the request)

public setUri(string|Http $uri) : $this
Parameters
$uri : string|Http
Return values
$this

calcAuthDigest()

Calculate the response value according to the HTTP authentication type

protected calcAuthDigest(string $user, string $password[, string $type = self::AUTH_BASIC ][, array<string|int, mixed> $digest = [] ][, null|string $entityBody = null ]) : string|bool
Parameters
$user : string
$password : string
$type : string = self::AUTH_BASIC
$digest : array<string|int, mixed> = []
$entityBody : null|string = null
Tags
see
http://www.faqs.org/rfcs/rfc2617.html
throws
InvalidArgumentException
Return values
string|bool

detectFileMimeType()

Attempt to detect the MIME type of a file using available extensions

protected detectFileMimeType(string $file) : string

This method will try to detect the MIME type of a file. If the fileinfo extension is available, it will be used. If not, the mime_magic extension which is deprecated but is still available in many PHP setups will be tried.

If neither extension is available, the default application/octet-stream MIME type will be returned

Parameters
$file : string

File path

Return values
string

MIME type

doRequest()

Separating this from send method allows subclasses to wrap the interaction with the adapter

protected doRequest(Http $uri, string $method[, bool $secure = false ][, array<string|int, mixed> $headers = [] ][, string $body = '' ]) : string
Parameters
$uri : Http
$method : string
$secure : bool = false
$headers : array<string|int, mixed> = []
$body : string = ''
Tags
throws
RuntimeException
Return values
string

the raw response

flattenParametersArray()

Convert an array of parameters into a flat array of (key, value) pairs

protected flattenParametersArray(array<string|int, mixed> $parray[, string $prefix = null ]) : array<string|int, mixed>

Will flatten a potentially multi-dimentional array of parameters (such as POST parameters) into a flat array of (key, value) paris. In case of multi-dimentional arrays, square brackets ([]) will be added to the key to indicate an array.

Parameters
$parray : array<string|int, mixed>
$prefix : string = null
Tags
since
1.9
Return values
array<string|int, mixed>

openTempStream()

Create temporary stream

protected openTempStream() : resource
Tags
throws
RuntimeException
Return values
resource

prepareBody()

Prepare the request body (for PATCH, POST and PUT requests)

protected prepareBody() : string
Tags
throws
RuntimeException
Return values
string

prepareCookies()

Prepare Cookies

protected prepareCookies(string $domain, string $path, bool $secure) : Cookie|bool
Parameters
$domain : string
$path : string
$secure : bool
Return values
Cookie|bool

prepareHeaders()

Prepare the request headers

protected prepareHeaders(resource|string $body, Http $uri) : array<string|int, mixed>
Parameters
$body : resource|string
$uri : Http
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

        
On this page

Search results