Client
extends AbstractHttp
in package
HTTP client class
Tags
Table of Contents
Properties
- $auth : Auth|null
- HTTP auth object
- $handler : HandlerInterface|null
- Request handler
- $multiHandler : CurlMulti|null
- Request multi-handler
- $options : array<string|int, mixed>
- Client options
- $request : AbstractRequest|null
- Request
- $response : AbstractResponse|null
- Response
Methods
- __call() : Response|Promise|array<string|int, mixed>|string
- Magic method to send requests by the method name, i.e. $client->get('http://localhost/');
- __callStatic() : Response|Promise|array<string|int, mixed>|string
- Magic method to send requests by the static method name, i.e. Client::get('http://localhost/');
- __construct() : mixed
- Instantiate the client object
- __toString() : string
- To string magic method to render the client request to a raw string
- addData() : Client
- Add data
- addFile() : Client
- Add file
- addHeader() : Client
- Add header
- addHeaders() : Client
- Add headers
- addOption() : Client
- Add an option
- addOptions() : Client
- Add options
- addQuery() : Client
- Add query
- createMulti() : CurlMulti
- Factory to create a multi-handler object
- fromCurlCommand() : Client
- Method to convert Curl CLI command to a client object
- getAuth() : Auth|null
- Get auth
- getBody() : Body|null
- Get request body
- getBodyContent() : string|null
- Get request body content
- getBodyContentLength() : int
- Get request body content length
- getData() : mixed
- Get data
- getFile() : string|null
- Get file
- getFiles() : array<string|int, mixed>|null
- Get files
- getHandler() : HandlerInterface|null
- Get handler
- getHeader() : mixed
- Get header
- getHeaders() : mixed
- Get headers
- getMethod() : string|null
- Get method
- getMultiHandler() : CurlMulti
- Get multi-handler
- getOption() : mixed
- Get options
- getOptions() : array<string|int, mixed>
- Get options
- getQuery() : mixed
- Get query
- getRequest() : AbstractRequest
- Get the request
- getResponse() : AbstractResponse
- Get the response
- getType() : mixed
- Get type
- hasAuth() : bool
- Has auth
- hasBody() : bool
- Has request body
- hasData() : bool
- Has data
- hasFile() : bool
- Has file
- hasFiles() : bool
- Has files
- hasHandler() : bool
- Has handler
- hasHeader() : bool
- Has header
- hasHeaders() : bool
- Has headers
- hasMethod() : bool
- Has method
- hasMultiHandler() : bool
- Has multi-handler
- hasOption() : bool
- Has option
- hasOptions() : bool
- Has options
- hasQuery() : bool
- Has query
- hasRequest() : bool
- Has request
- hasResponse() : bool
- Get the response
- hasType() : bool
- Has type
- isAccepted() : bool|null
- Determine if the response is 202 accepted
- isBadGateway() : bool|null
- Determine if the response is a 502 Bad Gateway
- isBadRequest() : bool|null
- Determine if the response is a 400 Bad Request
- isClientError() : bool|null
- Determine if the response is a client error
- isComplete() : bool
- Determine if the response is complete
- isConflict() : bool|null
- Determine if the response is a 409 Conflict
- isContinue() : bool|null
- Determine if the response is a continue
- isCreated() : bool|null
- Determine if the response is 201 created
- isError() : bool|null
- Determine if the response is an error
- isForbidden() : bool|null
- Determine if the response is a 403 Forbidden
- isFound() : bool|null
- Determine if the response is a 302 Found
- isInternalServerError() : bool|null
- Determine if the response is a 500 Internal Server Error
- isLengthRequired() : bool|null
- Determine if the response is a 411 Length Required
- isMethodNotAllowed() : bool|null
- Determine if the response is a 405 Method Not Allowed
- isMovedPermanently() : bool|null
- Determine if the response is a 301 Moved Permanently
- isNoContent() : bool|null
- Determine if the response is 204 No Content
- isNotAcceptable() : bool|null
- Determine if the response is a 406 Not Acceptable
- isNotFound() : bool|null
- Determine if the response is a 404 Not Found
- isOk() : bool|null
- Determine if the response is 200 OK
- isRedirect() : bool|null
- Determine if the response is a redirect
- isRequestTimeout() : bool|null
- Determine if the response is a 408 Request Timeout
- isServerError() : bool|null
- Determine if the response is a server error
- isServiceUnavailable() : bool|null
- Determine if the response is a 503 Service Unavailable
- isSuccess() : bool|null
- Determine if the response is a success
- isTooManyRequests() : bool|null
- Determine if the response is a 429 Too Many Requests
- isUnauthorized() : bool|null
- Determine if the response is a 401 Unauthorized
- isUnprocessableEntity() : bool|null
- Determine if the response is a 422 Unprocessable Entity
- isUnsupportedMediaType() : bool|null
- Determine if the response is a 415 Unsupported Media Type
- prepare() : Client
- Prepare the client request
- removeAllData() : Client
- Remove all data
- removeAllHeaders() : Client
- Remove all headers
- removeAllQuery() : Client
- Remove all query data
- removeBody() : Client
- Remove the body
- removeData() : Client
- Remove data
- removeFile() : Client
- Remove file
- removeFiles() : Client
- Remove all files
- removeHeader() : Client
- Remove header
- removeOption() : Client
- Remove option
- removeOptions() : Client
- Remove options
- removeQuery() : Client
- Remove query
- removeType() : Client
- Remove type
- render() : string
- Method to render the request as a string
- reset() : static
- Method to reset the client
- send() : Response|Promise|array<string|int, mixed>|string
- Send the client request
- sendAsync() : Promise
- Method to send the request asynchronously
- setAuth() : Client
- Set auth
- setBody() : Client
- Set request body
- setBodyFromFile() : Client
- Set request body from file
- setData() : Client
- Set data
- setFiles() : Client
- Set files
- setHandler() : Client
- Set handler
- setHeaders() : Client
- Set headers (clear out any existing headers)
- setMethod() : Client
- Set method
- setMultiHandler() : Client
- Set multi-handler
- setOptions() : Client
- Set options
- setQuery() : Client
- Set query
- setRequest() : AbstractHttp
- Set the request
- setResponse() : AbstractHttp
- Set the response
- setType() : Client
- Set type
- toCurlCommand() : string
- Method to convert client object to a Curl command for the CLI
Properties
$auth
HTTP auth object
protected
Auth|null
$auth
= null
$handler
Request handler
protected
HandlerInterface|null
$handler
= null
$multiHandler
Request multi-handler
protected
CurlMulti|null
$multiHandler
= null
$options
Client options
protected
array<string|int, mixed>
$options
= []
$request
Request
protected
AbstractRequest|null
$request
= null
$response
Response
protected
AbstractResponse|null
$response
= null
Methods
__call()
Magic method to send requests by the method name, i.e. $client->get('http://localhost/');
public
__call(string $methodName, array<string|int, mixed> $arguments) : Response|Promise|array<string|int, mixed>|string
Parameters
- $methodName : string
- $arguments : array<string|int, mixed>
Tags
Return values
Response|Promise|array<string|int, mixed>|string__callStatic()
Magic method to send requests by the static method name, i.e. Client::get('http://localhost/');
public
static __callStatic(string $methodName, array<string|int, mixed> $arguments) : Response|Promise|array<string|int, mixed>|string
Parameters
- $methodName : string
- $arguments : array<string|int, mixed>
Tags
Return values
Response|Promise|array<string|int, mixed>|string__construct()
Instantiate the client object
public
__construct() : mixed
Optional parameters are
- Request URI string
- Client request instance
- Client response instance
- Client handler instance
- Auth instance
- Options array
__toString()
To string magic method to render the client request to a raw string
public
__toString() : string
Return values
stringaddData()
Add data
public
addData(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientaddFile()
Add file
public
addFile(string $file[, string|null $name = null ]) : Client
Parameters
- $file : string
- $name : string|null = null
Tags
Return values
ClientaddHeader()
Add header
public
addHeader(Header|string|int $header[, mixed $value = null ]) : Client
Parameters
- $header : Header|string|int
- $value : mixed = null
Return values
ClientaddHeaders()
Add headers
public
addHeaders(array<string|int, mixed> $headers) : Client
Parameters
- $headers : array<string|int, mixed>
Return values
ClientaddOption()
Add an option
public
addOption(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientaddOptions()
Add options
public
addOptions(array<string|int, mixed> $options) : Client
Parameters
- $options : array<string|int, mixed>
Return values
ClientaddQuery()
Add query
public
addQuery(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientcreateMulti()
Factory to create a multi-handler object
public
static createMulti(array<string|int, mixed> $requests[, CurlMulti $multiHandler = new ClientHandlerCurlMulti() ]) : CurlMulti
Parameters
- $requests : array<string|int, mixed>
- $multiHandler : CurlMulti = new ClientHandlerCurlMulti()
Return values
CurlMultifromCurlCommand()
Method to convert Curl CLI command to a client object
public
static fromCurlCommand(string $command) : Client
Parameters
- $command : string
Tags
Return values
ClientgetAuth()
Get auth
public
getAuth() : Auth|null
Return values
Auth|nullgetBody()
Get request body
public
getBody() : Body|null
Return values
Body|nullgetBodyContent()
Get request body content
public
getBodyContent() : string|null
Return values
string|nullgetBodyContentLength()
Get request body content length
public
getBodyContentLength([bool $mb = false ]) : int
Parameters
- $mb : bool = false
Return values
intgetData()
Get data
public
getData([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getFile()
Get file
public
getFile(string $key) : string|null
Parameters
- $key : string
Return values
string|nullgetFiles()
Get files
public
getFiles() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetHandler()
Get handler
public
getHandler() : HandlerInterface|null
Return values
HandlerInterface|nullgetHeader()
Get header
public
getHeader(string $name) : mixed
Parameters
- $name : string
getHeaders()
Get headers
public
getHeaders() : mixed
getMethod()
Get method
public
getMethod() : string|null
Return values
string|nullgetMultiHandler()
Get multi-handler
public
getMultiHandler() : CurlMulti
Return values
CurlMultigetOption()
Get options
public
getOption(string $name) : mixed
Parameters
- $name : string
getOptions()
Get options
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getQuery()
Get query
public
getQuery([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getRequest()
Get the request
public
getRequest() : AbstractRequest
Return values
AbstractRequestgetResponse()
Get the response
public
getResponse() : AbstractResponse
Return values
AbstractResponsegetType()
Get type
public
getType() : mixed
hasAuth()
Has auth
public
hasAuth() : bool
Return values
boolhasBody()
Has request body
public
hasBody() : bool
Return values
boolhasData()
Has data
public
hasData([string|null $key = null ]) : bool
Parameters
- $key : string|null = null
Return values
boolhasFile()
Has file
public
hasFile(string $key) : bool
Parameters
- $key : string
Return values
boolhasFiles()
Has files
public
hasFiles() : bool
Return values
boolhasHandler()
Has handler
public
hasHandler() : bool
Return values
boolhasHeader()
Has header
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolhasHeaders()
Has headers
public
hasHeaders() : bool
Return values
boolhasMethod()
Has method
public
hasMethod() : bool
Return values
boolhasMultiHandler()
Has multi-handler
public
hasMultiHandler() : bool
Return values
boolhasOption()
Has option
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolhasOptions()
Has options
public
hasOptions() : bool
Return values
boolhasQuery()
Has query
public
hasQuery([string|null $key = null ]) : bool
Parameters
- $key : string|null = null
Return values
boolhasRequest()
Has request
public
hasRequest() : bool
Return values
boolhasResponse()
Get the response
public
hasResponse() : bool
Return values
boolhasType()
Has type
public
hasType() : bool
Return values
boolisAccepted()
Determine if the response is 202 accepted
public
isAccepted() : bool|null
Return values
bool|nullisBadGateway()
Determine if the response is a 502 Bad Gateway
public
isBadGateway() : bool|null
Return values
bool|nullisBadRequest()
Determine if the response is a 400 Bad Request
public
isBadRequest() : bool|null
Return values
bool|nullisClientError()
Determine if the response is a client error
public
isClientError() : bool|null
Return values
bool|nullisComplete()
Determine if the response is complete
public
isComplete() : bool
Return values
boolisConflict()
Determine if the response is a 409 Conflict
public
isConflict() : bool|null
Return values
bool|nullisContinue()
Determine if the response is a continue
public
isContinue() : bool|null
Return values
bool|nullisCreated()
Determine if the response is 201 created
public
isCreated() : bool|null
Return values
bool|nullisError()
Determine if the response is an error
public
isError() : bool|null
Return values
bool|nullisForbidden()
Determine if the response is a 403 Forbidden
public
isForbidden() : bool|null
Return values
bool|nullisFound()
Determine if the response is a 302 Found
public
isFound() : bool|null
Return values
bool|nullisInternalServerError()
Determine if the response is a 500 Internal Server Error
public
isInternalServerError() : bool|null
Return values
bool|nullisLengthRequired()
Determine if the response is a 411 Length Required
public
isLengthRequired() : bool|null
Return values
bool|nullisMethodNotAllowed()
Determine if the response is a 405 Method Not Allowed
public
isMethodNotAllowed() : bool|null
Return values
bool|nullisMovedPermanently()
Determine if the response is a 301 Moved Permanently
public
isMovedPermanently() : bool|null
Return values
bool|nullisNoContent()
Determine if the response is 204 No Content
public
isNoContent() : bool|null
Return values
bool|nullisNotAcceptable()
Determine if the response is a 406 Not Acceptable
public
isNotAcceptable() : bool|null
Return values
bool|nullisNotFound()
Determine if the response is a 404 Not Found
public
isNotFound() : bool|null
Return values
bool|nullisOk()
Determine if the response is 200 OK
public
isOk() : bool|null
Return values
bool|nullisRedirect()
Determine if the response is a redirect
public
isRedirect() : bool|null
Return values
bool|nullisRequestTimeout()
Determine if the response is a 408 Request Timeout
public
isRequestTimeout() : bool|null
Return values
bool|nullisServerError()
Determine if the response is a server error
public
isServerError() : bool|null
Return values
bool|nullisServiceUnavailable()
Determine if the response is a 503 Service Unavailable
public
isServiceUnavailable() : bool|null
Return values
bool|nullisSuccess()
Determine if the response is a success
public
isSuccess() : bool|null
Return values
bool|nullisTooManyRequests()
Determine if the response is a 429 Too Many Requests
public
isTooManyRequests() : bool|null
Return values
bool|nullisUnauthorized()
Determine if the response is a 401 Unauthorized
public
isUnauthorized() : bool|null
Return values
bool|nullisUnprocessableEntity()
Determine if the response is a 422 Unprocessable Entity
public
isUnprocessableEntity() : bool|null
Return values
bool|nullisUnsupportedMediaType()
Determine if the response is a 415 Unsupported Media Type
public
isUnsupportedMediaType() : bool|null
Return values
bool|nullprepare()
Prepare the client request
public
prepare([string|null $uri = null ][, string|null $method = null ]) : Client
Parameters
- $uri : string|null = null
- $method : string|null = null
Tags
Return values
ClientremoveAllData()
Remove all data
public
removeAllData() : Client
Return values
ClientremoveAllHeaders()
Remove all headers
public
removeAllHeaders() : Client
Return values
ClientremoveAllQuery()
Remove all query data
public
removeAllQuery() : Client
Return values
ClientremoveBody()
Remove the body
public
removeBody() : Client
Return values
ClientremoveData()
Remove data
public
removeData(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveFile()
Remove file
public
removeFile(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveFiles()
Remove all files
public
removeFiles() : Client
Return values
ClientremoveHeader()
Remove header
public
removeHeader(string $name) : Client
Parameters
- $name : string
Return values
ClientremoveOption()
Remove option
public
removeOption(string $name) : Client
Parameters
- $name : string
Return values
ClientremoveOptions()
Remove options
public
removeOptions() : Client
Return values
ClientremoveQuery()
Remove query
public
removeQuery(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveType()
Remove type
public
removeType() : Client
Return values
Clientrender()
Method to render the request as a string
public
render() : string
Return values
stringreset()
Method to reset the client
public
reset([bool $data = true ][, bool $headers = false ][, bool $clear = false ]) : static
Parameters
- $data : bool = true
- $headers : bool = false
- $clear : bool = false
Return values
staticsend()
Send the client request
public
send([string|null $uri = null ][, string|null $method = null ]) : Response|Promise|array<string|int, mixed>|string
Parameters
- $uri : string|null = null
- $method : string|null = null
Tags
Return values
Response|Promise|array<string|int, mixed>|stringsendAsync()
Method to send the request asynchronously
public
sendAsync() : Promise
Return values
PromisesetAuth()
Set auth
public
setAuth(Auth $auth) : Client
Parameters
- $auth : Auth
Return values
ClientsetBody()
Set request body
public
setBody(string $body) : Client
Parameters
- $body : string
Tags
Return values
ClientsetBodyFromFile()
Set request body from file
public
setBodyFromFile(string $file) : Client
Parameters
- $file : string
Tags
Return values
ClientsetData()
Set data
public
setData(array<string|int, mixed> $data) : Client
Parameters
- $data : array<string|int, mixed>
Return values
ClientsetFiles()
Set files
public
setFiles(array<string|int, mixed>|string $files[, bool $multipart = true ]) : Client
Parameters
- $files : array<string|int, mixed>|string
- $multipart : bool = true
Tags
Return values
ClientsetHandler()
Set handler
public
setHandler(HandlerInterface $handler) : Client
Parameters
- $handler : HandlerInterface
Return values
ClientsetHeaders()
Set headers (clear out any existing headers)
public
setHeaders(array<string|int, mixed> $headers) : Client
Parameters
- $headers : array<string|int, mixed>
Return values
ClientsetMethod()
Set method
public
setMethod(string $method) : Client
Parameters
- $method : string
Return values
ClientsetMultiHandler()
Set multi-handler
public
setMultiHandler(CurlMulti $multiHandler) : Client
Parameters
- $multiHandler : CurlMulti
Return values
ClientsetOptions()
Set options
public
setOptions(array<string|int, mixed> $options) : Client
Supported options
- 'base_uri'
- 'method'
- 'headers'
- 'user_agent'
- 'query' (can only be encoded query string on the URI)
- 'data' (can be any request data)
- 'files'
- 'type'
- 'auto'
- 'async'
- 'verify_peer'
- 'allow_self_signed'
- 'force_custom_method' (Curl only - forces CURLOPT_CUSTOMREQUEST)
Parameters
- $options : array<string|int, mixed>
Return values
ClientsetQuery()
Set query
public
setQuery(array<string|int, mixed> $query) : Client
Parameters
- $query : array<string|int, mixed>
Return values
ClientsetRequest()
Set the request
public
setRequest(AbstractRequest $request) : AbstractHttp
Parameters
- $request : AbstractRequest
Return values
AbstractHttpsetResponse()
Set the response
public
setResponse(AbstractResponse $response) : AbstractHttp
Parameters
- $response : AbstractResponse
Return values
AbstractHttpsetType()
Set type
public
setType(string $type[, bool $addHeader = true ]) : Client
Parameters
- $type : string
- $addHeader : bool = true
Return values
ClienttoCurlCommand()
Method to convert client object to a Curl command for the CLI
public
toCurlCommand() : string