ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilCurlConnection Class Reference
+ Collaboration diagram for ilCurlConnection:

Public Member Functions

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

Static Public Member Functions

static _isCurlExtensionLoaded ()
 Check if curl extension is loaded. More...
 

Protected Attributes

 $url = ''
 
 $ch = null
 

Private Member Functions

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

Private Attributes

 $header_plain = ''
 
 $header_arr = array()
 
 $response_body = ''
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilCurlConnection::__construct (   $a_url = '')

Constructor.

public

Parameters
stringurl for connection
Exceptions
ilCurlConnectionException

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

57  {
58  $this->url = $a_url;
59 
60  if(!self::_isCurlExtensionLoaded())
61  {
62  throw new ilCurlConnectionException('Curl extension not enabled.');
63  }
64  }

◆ __destruct()

ilCurlConnection::__destruct ( )

Destructor public.

Parameters

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

References close().

255  {
256  $this->close();
257  }
close()
Close connection.
+ Here is the call graph for this function:

Member Function Documentation

◆ _isCurlExtensionLoaded()

static ilCurlConnection::_isCurlExtensionLoaded ( )
staticfinal

Check if curl extension is loaded.

public

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

Referenced by ilLinkChecker\__validateLinks(), ilMediaImageUtil\getImageSize(), and ilClient\updateNIC().

74  {
75  if(!function_exists('curl_init'))
76  {
77  return false;
78  }
79  return true;
80  }
+ Here is the caller graph for this function:

◆ close()

ilCurlConnection::close ( )
final

Close connection.

public

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

Referenced by __destruct().

241  {
242  if($this->ch != null)
243  {
244  curl_close($this->ch);
245  $this->ch = null;
246  }
247  }
+ Here is the caller graph for this function:

◆ exec()

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

public

Parameters

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

References $res, and array.

156  {
157  // Add header function
158  curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
159  if((@$res = curl_exec($this->ch)) === false)
160  {
161  if(strlen($err = curl_error($this->ch)))
162  {
163  throw new ilCurlConnectionException($err, curl_errno($this->ch));
164  }
165  else
166  {
167  throw new ilCurlConnectionException('Error calling curl_exec().');
168  }
169  }
170  return $res;
171  }
Create styles array
The data for the language used.

◆ getInfo()

ilCurlConnection::getInfo (   $opt = 0)

Get informations about a specific transfer.

public

Parameters
intoption e.g CURLINFO_EFFECTIVE_URL
Returns
mixed

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

References $res.

Referenced by parseResponse().

203  {
204  if($opt)
205  {
206  $res = curl_getinfo($this->ch, $opt);
207  }
208  else
209  {
210  $res = curl_getinfo($this->ch);
211  }
212  return $res;
213  }
+ Here is the caller graph for this function:

◆ getResponseBody()

ilCurlConnection::getResponseBody ( )

Get responce body.

Returns
type

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

References $response_body.

190  {
191  return $this->response_body;
192  }

◆ getResponseHeader()

ilCurlConnection::getResponseHeader ( )

Get response header as string.

Returns
string

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

References $header_plain.

Referenced by parseHeader().

87  {
88  return $this->header_plain;
89  }
+ Here is the caller graph for this function:

◆ getResponseHeaderArray()

ilCurlConnection::getResponseHeaderArray ( )

Get response header as array.

Returns
array

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

References $header_arr, and array.

96  {
97  return (array) $this->header_arr;
98  }
Create styles array
The data for the language used.

◆ init()

ilCurlConnection::init ( )
final

Init curl connection.

public

Exceptions
ilCurlConnectionExceptionon error

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

Referenced by ilECSConnector\prepareConnection().

108  {
109  if(strlen($this->url))
110  {
111  $this->ch = curl_init($this->url);
112  #$GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->url);
113  }
114  else
115  {
116  $this->ch = curl_init();
117  }
118  if(!$this->ch)
119  {
120  throw new ilCurlConnectionException('Cannot init curl connection.');
121  }
122  if(curl_errno($this->ch))
123  {
124  throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
125  }
126 
127  return true;
128  }
+ Here is the caller graph for this function:

◆ parseHeader()

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

Parse respone header.

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

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

References $header, and getResponseHeader().

222  {
223  $this->header_plain = $header;
224 
225  $lines = explode('\r\n',$this->getResponseHeader());
226  foreach($lines as $line)
227  {
228  list($name,$value) = explode(':',$line,2);
229  $this->header_arr[$name] = $value;
230  }
231  return strlen($this->getResponseHeader());
232  }
$header
getResponseHeader()
Get response header as string.
+ Here is the call graph for this function:

◆ parseResponse()

ilCurlConnection::parseResponse (   $a_response)

parse response body

Parameters
type$a_response

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

References getInfo().

178  {
179  $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
180 
181  $this->header_plain = substr($a_response, 0, $header_size);
182  $this->response_body = substr($a_response, $header_size);
183  }
getInfo($opt=0)
Get informations about a specific transfer.
+ Here is the call graph for this function:

◆ setOpt()

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 139 of file class.ilCurlConnection.php.

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

Field Documentation

◆ $ch

ilCurlConnection::$ch = null
protected

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

◆ $header_arr

ilCurlConnection::$header_arr = array()
private

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

Referenced by getResponseHeaderArray().

◆ $header_plain

ilCurlConnection::$header_plain = ''
private

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

Referenced by getResponseHeader().

◆ $response_body

ilCurlConnection::$response_body = ''
private

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

Referenced by getResponseBody().

◆ $url

ilCurlConnection::$url = ''
protected

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


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