PHP Class Ixudra\Curl\Builder

Show file Open project: ixudra/curl

Protected Properties

Property Type Description
$curlObject resource cURL request
$curlOptions array Array of cURL options
$packageOptions array Array with options that are not specific to cURL but are used by the package

Public Methods

Method Description
allowRedirect ( ) : Builder Allow for redirects in the request
asJson ( boolean $asArray = false ) : Builder Configure the package to encode and decode the request data
asJsonRequest ( ) : Builder Configure the package to encode the request data to json before sending it to the server
asJsonResponse ( boolean $asArray = false ) : Builder Configure the package to decode the request data from json to object or associative array
containsFile ( ) : Builder Enable File sending
delete ( ) : mixed Send a DELETE request to a URL using the specified cURL options
download ( string $fileName ) : mixed Send a download request to a URL using the specified cURL options
enableDebug ( string $logFile ) : Builder Enable debug mode for the cURL request
get ( ) : mixed Send a GET request to a URL using the specified cURL options
patch ( ) : mixed Send a PATCH request to a URL using the specified cURL options
post ( ) : mixed Send a POST request to a URL using the specified cURL options
put ( ) : mixed Send a PUT request to a URL using the specified cURL options
returnResponseObject ( ) : Builder Return a full response object with HTTP status and headers instead of only the content
to ( $url ) : Builder Set the URL to which the request is to be sent
withContentType ( string $contentType ) : Builder Add a content type HTTP header to the request
withData ( array $data = [] ) : Builder Add GET or POST data to the request
withHeader ( string $header ) : Builder Add a HTTP header to the request
withHeaders ( array $headers ) : Builder Add multiple HTTP header at the same time to the request
withOption ( string $key, string $value ) : Builder Set any specific cURL option
withTimeout ( integer $timeout = 30 ) : Builder Set the request timeout

Protected Methods

Method Description
appendDataToURL ( ) : string Append set data to the query string for GET and DELETE cURL requests
forgeOptions ( ) : array Convert the curlOptions to an array of usable options for the cURL request
returnResponse ( mixed $content, array $responseData = [] ) : stdClas\stdClass
send ( ) : mixed Send the request
setPostParameters ( ) Add POST parameters to the curlOptions array
withCurlOption ( string $key, string $value ) : Builder Set any specific cURL option
withPackageOption ( string $key, string $value ) : Builder Set any specific package option

Method Details

allowRedirect() public method

Allow for redirects in the request
public allowRedirect ( ) : Builder
return Builder

appendDataToURL() protected method

Append set data to the query string for GET and DELETE cURL requests
protected appendDataToURL ( ) : string
return string

asJson() public method

Configure the package to encode and decode the request data
public asJson ( boolean $asArray = false ) : Builder
$asArray boolean Indicates whether or not the data should be returned as an array. Default: false
return Builder

asJsonRequest() public method

Configure the package to encode the request data to json before sending it to the server
public asJsonRequest ( ) : Builder
return Builder

asJsonResponse() public method

Configure the package to decode the request data from json to object or associative array
public asJsonResponse ( boolean $asArray = false ) : Builder
$asArray boolean Indicates whether or not the data should be returned as an array. Default: false
return Builder

containsFile() public method

Enable File sending
public containsFile ( ) : Builder
return Builder

delete() public method

Send a DELETE request to a URL using the specified cURL options
public delete ( ) : mixed
return mixed

download() public method

Send a download request to a URL using the specified cURL options
public download ( string $fileName ) : mixed
$fileName string
return mixed

enableDebug() public method

Enable debug mode for the cURL request
public enableDebug ( string $logFile ) : Builder
$logFile string The full path to the log file you want to use
return Builder

forgeOptions() protected method

Convert the curlOptions to an array of usable options for the cURL request
protected forgeOptions ( ) : array
return array

get() public method

Send a GET request to a URL using the specified cURL options
public get ( ) : mixed
return mixed

patch() public method

Send a PATCH request to a URL using the specified cURL options
public patch ( ) : mixed
return mixed

post() public method

Send a POST request to a URL using the specified cURL options
public post ( ) : mixed
return mixed

put() public method

Send a PUT request to a URL using the specified cURL options
public put ( ) : mixed
return mixed

returnResponse() protected method

protected returnResponse ( mixed $content, array $responseData = [] ) : stdClas\stdClass
$content mixed Content of the request
$responseData array Additional response information
return stdClas\stdClass

returnResponseObject() public method

Return a full response object with HTTP status and headers instead of only the content
public returnResponseObject ( ) : Builder
return Builder

send() protected method

Send the request
protected send ( ) : mixed
return mixed

setPostParameters() protected method

Add POST parameters to the curlOptions array
protected setPostParameters ( )

to() public method

Set the URL to which the request is to be sent
public to ( $url ) : Builder
$url string The URL to which the request is to be sent
return Builder

withContentType() public method

Add a content type HTTP header to the request
public withContentType ( string $contentType ) : Builder
$contentType string The content type of the file you would like to download
return Builder

withCurlOption() protected method

Set any specific cURL option
protected withCurlOption ( string $key, string $value ) : Builder
$key string The name of the cURL option
$value string The value to which the option is to be set
return Builder

withData() public method

Add GET or POST data to the request
public withData ( array $data = [] ) : Builder
$data array Array of data that is to be sent along with the request
return Builder

withHeader() public method

Add a HTTP header to the request
public withHeader ( string $header ) : Builder
$header string The HTTP header that is to be added to the request
return Builder

withHeaders() public method

Add multiple HTTP header at the same time to the request
public withHeaders ( array $headers ) : Builder
$headers array Array of HTTP headers that must be added to the request
return Builder

withOption() public method

Set any specific cURL option
public withOption ( string $key, string $value ) : Builder
$key string The name of the cURL option
$value string The value to which the option is to be set
return Builder

withPackageOption() protected method

Set any specific package option
protected withPackageOption ( string $key, string $value ) : Builder
$key string The name of the cURL option
$value string The value to which the option is to be set
return Builder

withTimeout() public method

Set the request timeout
public withTimeout ( integer $timeout = 30 ) : Builder
$timeout integer The timeout for the request (in seconds. Default: 30 seconds)
return Builder

Property Details

$curlObject protected property

cURL request
protected resource $curlObject
return resource

$curlOptions protected property

Array of cURL options
protected array $curlOptions
return array

$packageOptions protected property

Array with options that are not specific to cURL but are used by the package
protected array $packageOptions
return array