ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  throw new ilCurlConnectionException('Curl extension not enabled.');
62  }
63  }

◆ __destruct()

ilCurlConnection::__destruct ( )

Destructor public.

Parameters

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

References close().

238  {
239  $this->close();
240  }
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 72 of file class.ilCurlConnection.php.

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

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

◆ close()

ilCurlConnection::close ( )
final

Close connection.

public

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

Referenced by __destruct().

225  {
226  if ($this->ch != null) {
227  curl_close($this->ch);
228  $this->ch = null;
229  }
230  }
+ Here is the caller graph for this function:

◆ exec()

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

public

Parameters

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

References $res, and array.

148  {
149  // Add header function
150  curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
151  if ((@$res = curl_exec($this->ch)) === false) {
152  if (strlen($err = curl_error($this->ch))) {
153  throw new ilCurlConnectionException($err, curl_errno($this->ch));
154  } else {
155  throw new ilCurlConnectionException('Error calling curl_exec().');
156  }
157  }
158  return $res;
159  }
foreach($_POST as $key=> $value) $res
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 190 of file class.ilCurlConnection.php.

References $res.

Referenced by parseResponse().

191  {
192  if ($opt) {
193  $res = curl_getinfo($this->ch, $opt);
194  } else {
195  $res = curl_getinfo($this->ch);
196  }
197  return $res;
198  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ getResponseBody()

ilCurlConnection::getResponseBody ( )

Get responce body.

Returns
type

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

References $response_body.

178  {
179  return $this->response_body;
180  }

◆ getResponseHeader()

ilCurlConnection::getResponseHeader ( )

Get response header as string.

Returns
string

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

References $header_plain.

Referenced by parseHeader().

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

◆ getResponseHeaderArray()

ilCurlConnection::getResponseHeaderArray ( )

Get response header as array.

Returns
array

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

References $header_arr, and array.

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

◆ init()

ilCurlConnection::init ( )
final

Init curl connection.

public

Exceptions
ilCurlConnectionExceptionon error

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

Referenced by ilECSConnector\prepareConnection().

106  {
107  if (strlen($this->url)) {
108  $this->ch = curl_init($this->url);
109  #$GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->url);
110  } else {
111  $this->ch = curl_init();
112  }
113  if (!$this->ch) {
114  throw new ilCurlConnectionException('Cannot init curl connection.');
115  }
116  if (curl_errno($this->ch)) {
117  throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
118  }
119 
120  return true;
121  }
+ 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 206 of file class.ilCurlConnection.php.

References $header, $name, and getResponseHeader().

207  {
208  $this->header_plain = $header;
209 
210  $lines = explode('\r\n', $this->getResponseHeader());
211  foreach ($lines as $line) {
212  list($name, $value) = explode(':', $line, 2);
213  $this->header_arr[$name] = $value;
214  }
215  return strlen($this->getResponseHeader());
216  }
if($format !==null) $name
Definition: metadata.php:146
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 165 of file class.ilCurlConnection.php.

References getInfo().

166  {
167  $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
168 
169  $this->header_plain = substr($a_response, 0, $header_size);
170  $this->response_body = substr($a_response, $header_size);
171  }
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 132 of file class.ilCurlConnection.php.

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

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: