ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilCurlConnection Class Reference
+ Collaboration diagram for ilCurlConnection:

Public Member Functions

 __construct ($a_url= '')
 Constructor.
 getResponseHeader ()
 Get response header as string.
 getResponseHeaderArray ()
 Get response header as array.
 init ()
 Init curl connection.
 setOpt ($a_option, $a_value)
 Wrapper for curl_setopt.
 exec ()
 Wrapper for curl_exec.
 getInfo ($opt=0)
 Get informations about a specific transfer.
 close ()
 Close connection.
 __destruct ()
 Destructor.

Static Public Member Functions

static _isCurlExtensionLoaded ()
 Check if curl extension is loaded.

Protected Attributes

 $url = ''
 $ch = null

Private Member Functions

 parseHeader ($handle, $header)
 Parse respone header.

Private Attributes

 $header_plain = ''
 $header_arr = array()

Detailed Description

Definition at line 38 of file class.ilCurlConnection.php.

Constructor & Destructor Documentation

ilCurlConnection::__construct (   $a_url = '')

Constructor.

public

Parameters
stringurl for connection
Exceptions
ilCurlConnectionException

Definition at line 54 of file class.ilCurlConnection.php.

{
$this->url = $a_url;
if(!self::_isCurlExtensionLoaded())
{
throw new ilCurlConnectionException('Curl extension not enabled.');
}
}
ilCurlConnection::__destruct ( )

Destructor.

public

Parameters

Definition at line 232 of file class.ilCurlConnection.php.

References close().

{
$this->close();
}

+ Here is the call graph for this function:

Member Function Documentation

static ilCurlConnection::_isCurlExtensionLoaded ( )
staticfinal

Check if curl extension is loaded.

public

Definition at line 71 of file class.ilCurlConnection.php.

{
if(!function_exists('curl_init'))
{
return false;
}
return true;
}
ilCurlConnection::close ( )
final

Close connection.

public

Definition at line 217 of file class.ilCurlConnection.php.

Referenced by __destruct().

{
if($this->ch != null)
{
curl_close($this->ch);
}
}

+ Here is the caller graph for this function:

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

public

Parameters

Definition at line 153 of file class.ilCurlConnection.php.

References $res.

{
// Add header function
curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
if((@$res = curl_exec($this->ch)) === false)
{
if(strlen($err = curl_error($this->ch)))
{
throw new ilCurlConnectionException($err, curl_errno($this->ch));
}
else
{
throw new ilCurlConnectionException('Error calling curl_exec().');
}
}
return $res;
}
ilCurlConnection::getInfo (   $opt = 0)

Get informations about a specific transfer.

public

Parameters
intoption e.g CURLINFO_EFFECTIVE_URL
Returns
mixed

Definition at line 179 of file class.ilCurlConnection.php.

References $res.

{
if($opt)
{
$res = curl_getinfo($this->ch, $opt);
}
else
{
$res = curl_getinfo($this->ch);
}
return $res;
}
ilCurlConnection::getResponseHeader ( )

Get response header as string.

Returns
string

Definition at line 84 of file class.ilCurlConnection.php.

References $header_plain.

Referenced by parseHeader().

{
}

+ Here is the caller graph for this function:

ilCurlConnection::getResponseHeaderArray ( )

Get response header as array.

Returns
array

Definition at line 93 of file class.ilCurlConnection.php.

References $header_arr.

{
return (array) $this->header_arr;
}
ilCurlConnection::init ( )
final

Init curl connection.

public

Exceptions
ilCurlConnectionExceptionon error

Definition at line 105 of file class.ilCurlConnection.php.

Referenced by ilECSConnector\prepareConnection().

{
if(strlen($this->url))
{
$this->ch = curl_init($this->url);
#$GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->url);
}
else
{
$this->ch = curl_init();
}
if(!$this->ch)
{
throw new ilCurlConnectionException('Cannot init curl connection.');
}
if(curl_errno($this->ch))
{
throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
}
return true;
}

+ Here is the caller graph for this function:

ilCurlConnection::parseHeader (   $handle,
  $header 
)
private

Parse respone header.

Parameters
mixed$handle
string$header
Returns
int strlen of header

Definition at line 198 of file class.ilCurlConnection.php.

References getResponseHeader().

{
$this->header_plain = $header;
$lines = explode('\r\n',$this->getResponseHeader());
foreach($lines as $line)
{
list($name,$value) = explode(':',$line,2);
$this->header_arr[$name] = $value;
}
return strlen($this->getResponseHeader());
}

+ Here is the call graph for this function:

ilCurlConnection::setOpt (   $a_option,
  $a_value 
)
final

Wrapper for curl_setopt.

public

Parameters
intCURL_OPTION
mixedbool string or resource
Exceptions
ilCurlConnectionExceptionon error

Definition at line 137 of file class.ilCurlConnection.php.

{
if(!@curl_setopt($this->ch, $a_option, $a_value))
{
throw new ilCurlConnectionException('Invalid option given for: ' . $a_option, curl_errno($this->ch));
}
return true;
}

Field Documentation

ilCurlConnection::$ch = null
protected

Definition at line 41 of file class.ilCurlConnection.php.

ilCurlConnection::$header_arr = array()
private

Definition at line 44 of file class.ilCurlConnection.php.

Referenced by getResponseHeaderArray().

ilCurlConnection::$header_plain = ''
private

Definition at line 43 of file class.ilCurlConnection.php.

Referenced by getResponseHeader().

ilCurlConnection::$url = ''
protected

Definition at line 40 of file class.ilCurlConnection.php.


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