ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
XML_RPC2_Util_HTTPRequest Class Reference
+ Collaboration diagram for XML_RPC2_Util_HTTPRequest:

Public Member Functions

 getBody ()
 body field getter
 setPostData ($value)
 postData field setter
 __construct ($uri= '', $params=array())
 Constructor.
 sendRequest ()
 Sends the request.

Private Attributes

 $_proxy = null
 $_proxyAuth = null
 $_postData
 $_uri
 $_encoding = 'iso-8859-1'
 $_sslverify = true

Detailed Description

Definition at line 58 of file HTTPRequest.php.

Constructor & Destructor Documentation

XML_RPC2_Util_HTTPRequest::__construct (   $uri = '',
  $params = array() 
)

Constructor.

Sets up the object

Parameters
stringThe uri to fetch/access
arrayAssociative array of parameters which can have the following keys:
  • proxy - Proxy (string)
  • encoding - The request encoding (string)
public

Definition at line 146 of file HTTPRequest.php.

{
if (!preg_match('/(https?:\/\/)(.*)/', $uri)) throw new XML_RPC2_Exception('Unable to parse URI');
$this->_uri = $uri;
if (isset($params['encoding'])) {
$this->_encoding = $params['encoding'];
}
if (isset($params['proxy'])) {
$proxy = $params['proxy'];
$elements = parse_url($proxy);
if (is_array($elements)) {
if ((isset($elements['scheme'])) and (isset($elements['host']))) {
$this->_proxy = $elements['scheme'] . '://' . $elements['host'];
}
if (isset($elements['port'])) {
$this->_proxy = $this->_proxy . ':' . $elements['port'];
}
if ((isset($elements['user'])) and (isset($elements['pass']))) {
$this->_proxyAuth = $elements['user'] . ':' . $elements['pass'];
}
}
}
if (isset($params['sslverify'])) {
$this->_sslverify = $params['sslverify'];
}
}

Member Function Documentation

XML_RPC2_Util_HTTPRequest::getBody ( )

body field getter

Returns
string body value

Definition at line 113 of file HTTPRequest.php.

{
return $this->_body;
}
XML_RPC2_Util_HTTPRequest::sendRequest ( )

Sends the request.

public

Returns
mixed PEAR error on error, true otherwise

Definition at line 182 of file HTTPRequest.php.

References $result, and XML_RPC2_Client\VERSION.

{
if (!function_exists('curl_init') &&
!( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely)
@dl('php_curl' . PHP_SHLIB_SUFFIX) || @dl('curl' . PHP_SHLIB_SUFFIX)
)) {
throw new XML_RPC2_CurlException('cURI extension is not present and load failed');
}
if ($ch = curl_init()) {
if (
(is_null($this->_proxy) || curl_setopt($ch, CURLOPT_PROXY, $this->_proxy)) &&
(is_null($this->_proxyAuth) || curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->_proxyAuth)) &&
curl_setopt($ch, CURLOPT_URL, $this->_uri) &&
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) &&
curl_setopt($ch, CURLOPT_POST, 1) &&
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_sslverify) &&
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml; charset='.$this->_encoding, 'User-Agent: PEAR_XML_RCP2/' . XML_RPC2_Client::VERSION)) &&
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postData)
) {
$result = curl_exec($ch);
if (($errno = curl_errno($ch)) != 0) {
throw new XML_RPC2_CurlException("Curl returned non-null errno $errno:" . curl_error($ch));
}
$info = curl_getinfo($ch);
if ($info['http_code'] != 200) {
throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non 200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result);
}
} else {
throw new XML_RPC2_CurlException('Unable to setup curl');
}
} else {
throw new XML_RPC2_CurlException('Unable to init curl');
}
$this->_body = $result;
return true;
}
XML_RPC2_Util_HTTPRequest::setPostData (   $value)

postData field setter

Parameters
stringpostData value

Definition at line 126 of file HTTPRequest.php.

{
$this->_postData = $value;
}

Field Documentation

XML_RPC2_Util_HTTPRequest::$_encoding = 'iso-8859-1'
private

Definition at line 96 of file HTTPRequest.php.

XML_RPC2_Util_HTTPRequest::$_postData
private

Definition at line 82 of file HTTPRequest.php.

XML_RPC2_Util_HTTPRequest::$_proxy = null
private

Definition at line 68 of file HTTPRequest.php.

XML_RPC2_Util_HTTPRequest::$_proxyAuth = null
private

Definition at line 75 of file HTTPRequest.php.

XML_RPC2_Util_HTTPRequest::$_sslverify = true
private

Definition at line 103 of file HTTPRequest.php.

XML_RPC2_Util_HTTPRequest::$_uri
private

Definition at line 89 of file HTTPRequest.php.


The documentation for this class was generated from the following file: