PHP Class Bart\Curl

Datei anzeigen Open project: box/bart Class Usage Examples

Public Methods

Method Description
__construct ( $hostUri, $port = 80 ) Curl to $hostUri on $port
delete ( $path, array $getParams, array $headers = null, null $cookies = null ) : array HTTP Delete Request
get ( string $path, array $getParams, array $headers = null, array $cookies = null ) : array
post ( string $path, array $getParams, string | array $postData, array $headers = null, string $cookies = null ) : array HTTP Post Request
put ( string $path, array $getParams, mixed $body = null, array $headers = null, string $cookies = null ) : array PUT a json body
setAuth ( string $user, string $pwd, integer $method = CURLAUTH_BASIC ) Set any authentication credentials desired for request(s)
setPhpCurlOpts ( array $curlOpts ) Fall back method to set your own curl options not currenctly explicitly support

Private Methods

Method Description
buildFullPath ( $subUri )
buildFullUri ( string $path, string[] $getVars ) : string build the full URI request
parseHeaders ( $headerString ) : array Parse the headers into an array that matches that pattern of http://php.net/manual/en/function.http-parse-headers.php
request ( $httpMethod, $path, array $getParams, $body, array $headers = null, $cookies = null )

Method Details

__construct() public method

Curl to $hostUri on $port
public __construct ( $hostUri, $port = 80 )

delete() public method

HTTP Delete Request
public delete ( $path, array $getParams, array $headers = null, null $cookies = null ) : array
$path
$getParams array
$headers array
$cookies null
return array

get() public method

public get ( string $path, array $getParams, array $headers = null, array $cookies = null ) : array
$path string The resource path to be appended to the base URI
$getParams array key-value pairs
$headers array array of valid HTTP header strings; e.g. ['Accept: application/json']
$cookies array The contents of the "Cookie: " header to be used in the HTTP request. Note that multiple cookies are separated with a semicolon followed by a space
return array Response and info

post() public method

HTTP Post Request
public post ( string $path, array $getParams, string | array $postData, array $headers = null, string $cookies = null ) : array
$path string relative path from base hostUri
$getParams array An associative array of get parameters
$postData string | array The data to send in your post
$headers array associative array of headers to include
$cookies string Cookies to include
return array Remote response body

put() public method

PUT a json body
public put ( string $path, array $getParams, mixed $body = null, array $headers = null, string $cookies = null ) : array
$path string relative path from base hostUri
$getParams array An associative array of get parameters
$body mixed Optional array or string request body data to send
$headers array Optional headers to send with PUT
$cookies string Cookies to include
return array Remote response body

setAuth() public method

Set any authentication credentials desired for request(s)
public setAuth ( string $user, string $pwd, integer $method = CURLAUTH_BASIC )
$user string
$pwd string
$method integer (optional) Curl constant for the auth method type

setPhpCurlOpts() public method

Fall back method to set your own curl options not currenctly explicitly support
public setPhpCurlOpts ( array $curlOpts )
$curlOpts array An array specifying which options to set and their values. The keys must be valid curl_setopt() constants or their integer equivalents.