PHP Class HttpRequestService, thinksns

ファイルを表示 Open project: medz/thinksns-4 Class Usage Examples

Public Properties

Property Type Description
$_encode default is json
$api_url #Set up the API root URL.
$connecttimeout #Set connect timeout.
$decodeFormat Only support json & xml for extension
$format #Response format.
$http_code #Contains the last HTTP status code returned.
$http_header
$http_info #Contains the last HTTP headers returned.
$ssl_verifypeer #Verify SSL Cert.
$timeout #Set timeout default.

Public Methods

Method Description
_DELETE ( $url, $params = null, $username = null, $password = null ) : RESTClient DELETE wrapper for delete data
_GET ( $url, $params = null, $username = null, $password = null ) : RESTClient GET wrapper for get data
_POST ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient POST wrapper for insert data
_POST_FOPEN ( $url, $params = null, $username = null, $password = null, $contentType = null )
_PUT ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient PUT wrapper for update data
__construct ( )
_photoUpload ( $url, $postdata, $files )
call ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null ) : RESTClient Execute calls
call_fopen ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null )
close ( ) Closes the connection and release resources
convertEncoding ( $source, $in, $out )
create_post_body ( $post_params )
do_post_request ( $url, $postdata, $files ) : mixed POST wrapper,不基于curl函数,环境可以不支持curl函数
getHeader ( $ch, $header ) Get the header info to store.
get_http_url ( ) parses the url and rebuilds it to be scheme://host/path
json_foreach ( $jsonArr ) 将stdclass object转换成数组,并转换编码
objectToArray ( $obj )
parseResponse ( $resp, $ext = '' ) * Parse response, including json, xml, plain text
setAuthorizeInfo ( $username, $password ) Set the authorize info for Basic Authentication
setContentType ( string $contentType ) Set the Content-Type of the request to be send Format like "application/json" or "application/xml" or "text/plain" or other
setDecodeFormat ( $format = null ) : boolean Sets the format type to be decoded
setEncode ( $encode )
setFormat ( $format = null ) : boolean Sets the format type to be extension
setMethod ( $method ) Set the Request HTTP Method
setNotFollow ( ) : RESTClient Settings that won't follow redirects
setParameters ( $params ) Set Parameters to be send on the request It can be both a key/value par array (as in array("key"=>"value")) or a string containing the body of the request, like a XML, JSON or other Proper content-type should be set for the body if not a array
setURL ( $url ) Sets the URL to be Called
to_postdata ( ) builds the data one would send in a POST request
to_url ( ) builds a url usable for a GET request
xml_decode ( $data, $toArray = false ) * XML decode

Method Details

_DELETE() public method

DELETE wrapper for delete data
public _DELETE ( $url, $params = null, $username = null, $password = null ) : RESTClient
$url String
$params mixed
$username String
$password String
return RESTClient

_GET() public method

GET wrapper for get data
public _GET ( $url, $params = null, $username = null, $password = null ) : RESTClient
$url String
$params mixed
$username String
$password String
return RESTClient

_POST() public method

POST wrapper for insert data
public _POST ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$params mixed
$username String
$password String
$contentType String
return RESTClient

_POST_FOPEN() public method

public _POST_FOPEN ( $url, $params = null, $username = null, $password = null, $contentType = null )

_PUT() public method

PUT wrapper for update data
public _PUT ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$params mixed
$username String
$password String
$contentType String
return RESTClient

__construct() public method

public __construct ( )

_photoUpload() public method

public _photoUpload ( $url, $postdata, $files )

call() public method

Execute calls
public call ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$method String
$postFields String
$username String
$password String
$contentType String
return RESTClient

call_fopen() public method

public call_fopen ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null )

close() public method

Closes the connection and release resources
public close ( )

convertEncoding() public static method

public static convertEncoding ( $source, $in, $out )

create_post_body() public method

public create_post_body ( $post_params )

do_post_request() public method

POST wrapper,不基于curl函数,环境可以不支持curl函数
public do_post_request ( $url, $postdata, $files ) : mixed
return mixed

getHeader() public method

Get the header info to store.
public getHeader ( $ch, $header )

get_http_url() public method

parses the url and rebuilds it to be scheme://host/path
public get_http_url ( )

json_foreach() public method

将stdclass object转换成数组,并转换编码
public json_foreach ( $jsonArr )

objectToArray() public static method

public static objectToArray ( $obj )

parseResponse() public method

* Parse response, including json, xml, plain text
public parseResponse ( $resp, $ext = '' )
$resp String
$ext String, including json/xml

setAuthorizeInfo() public method

Set the authorize info for Basic Authentication
public setAuthorizeInfo ( $username, $password )
$username String
$password String

setContentType() public method

Set the Content-Type of the request to be send Format like "application/json" or "application/xml" or "text/plain" or other
public setContentType ( string $contentType )
$contentType string

setDecodeFormat() public method

Sets the format type to be decoded
public setDecodeFormat ( $format = null ) : boolean
$format String
return boolean

setEncode() public method

public setEncode ( $encode )

setFormat() public method

Sets the format type to be extension
public setFormat ( $format = null ) : boolean
$format String
return boolean

setMethod() public method

Set the Request HTTP Method
public setMethod ( $method )
$method String

setNotFollow() public method

Settings that won't follow redirects
public setNotFollow ( ) : RESTClient
return RESTClient

setParameters() public method

Set Parameters to be send on the request It can be both a key/value par array (as in array("key"=>"value")) or a string containing the body of the request, like a XML, JSON or other Proper content-type should be set for the body if not a array
public setParameters ( $params )
$params mixed

setURL() public method

Sets the URL to be Called
public setURL ( $url )
$url String

to_postdata() public method

builds the data one would send in a POST request
public to_postdata ( )

to_url() public method

builds a url usable for a GET request
public to_url ( )

xml_decode() public static method

* XML decode
public static xml_decode ( $data, $toArray = false )
$data String
$toArray boolean, true for make it be array

Property Details

$_encode public_oe property

default is json
public $_encode

$api_url public_oe property

#Set up the API root URL.
public $api_url

$connecttimeout public_oe property

#Set connect timeout.
public $connecttimeout

$decodeFormat public_oe property

Only support json & xml for extension
public $decodeFormat

$format public_oe property

#Response format.
public $format

$http_code public_oe property

#Contains the last HTTP status code returned.
public $http_code

$http_header public_oe property

public $http_header

$http_info public_oe property

#Contains the last HTTP headers returned.
public $http_info

$ssl_verifypeer public_oe property

#Verify SSL Cert.
public $ssl_verifypeer

$timeout public_oe property

#Set timeout default.
public $timeout