ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 @access 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.

@access 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 @access public.

Parameters

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

240 {
241 $this->close();
242 }
close()
Close connection.

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ _isCurlExtensionLoaded()

static ilCurlConnection::_isCurlExtensionLoaded ( )
staticfinal

Check if curl extension is loaded.

@access public

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

73 {
74 if (!function_exists('curl_init')) {
75 return false;
76 }
77 return true;
78 }

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

+ Here is the caller graph for this function:

◆ close()

ilCurlConnection::close ( )
final

Close connection.

@access public

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

227 {
228 if ($this->ch != null) {
229 curl_close($this->ch);
230 $this->ch = null;
231 }
232 }

Referenced by __destruct(), and init().

+ Here is the caller graph for this function:

◆ exec()

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

@access public

Parameters

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

150 {
151 // Add header function
152 curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
153 if ((@$res = curl_exec($this->ch)) === false) {
154 if (strlen($err = curl_error($this->ch))) {
155 throw new ilCurlConnectionException($err, curl_errno($this->ch));
156 } else {
157 throw new ilCurlConnectionException('Error calling curl_exec().');
158 }
159 }
160 return $res;
161 }
foreach($_POST as $key=> $value) $res

References $res.

◆ getInfo()

ilCurlConnection::getInfo (   $opt = 0)

Get informations about a specific transfer.

@access public

Parameters
intoption e.g CURLINFO_EFFECTIVE_URL
Returns
mixed

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

193 {
194 if ($opt) {
195 $res = curl_getinfo($this->ch, $opt);
196 } else {
197 $res = curl_getinfo($this->ch);
198 }
199 return $res;
200 }

References $res.

Referenced by parseResponse().

+ Here is the caller graph for this function:

◆ getResponseBody()

ilCurlConnection::getResponseBody ( )

Get responce body.

Returns
type

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

References $response_body.

◆ 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().

+ 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.

94 {
95 return (array) $this->header_arr;
96 }

References $header_arr.

◆ init()

ilCurlConnection::init ( )
final

Init curl connection.

@access public

Exceptions
ilCurlConnectionExceptionon error

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

106 {
107 // teminate existing handles
108 $this->close();
109 if (strlen($this->url)) {
110 $this->ch = curl_init($this->url);
111 #$GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ' . $this->url);
112 } else {
113 $this->ch = curl_init();
114 }
115 if (!$this->ch) {
116 throw new ilCurlConnectionException('Cannot init curl connection.');
117 }
118 if (curl_errno($this->ch)) {
119 throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
120 }
121
122 return true;
123 }

References close().

+ Here is the call 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 208 of file class.ilCurlConnection.php.

209 {
210 $this->header_plain = $header;
211
212 $lines = explode('\r\n', $this->getResponseHeader());
213 foreach ($lines as $line) {
214 list($name, $value) = explode(':', $line, 2);
215 $this->header_arr[$name] = $value;
216 }
217 return strlen($this->getResponseHeader());
218 }
getResponseHeader()
Get response header as string.

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

+ Here is the call graph for this function:

◆ parseResponse()

ilCurlConnection::parseResponse (   $a_response)

parse response body

Parameters
type$a_response

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

168 {
169 $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
170
171 $this->header_plain = substr($a_response, 0, $header_size);
172 $this->response_body = substr($a_response, $header_size);
173 }
getInfo($opt=0)
Get informations about a specific transfer.

References getInfo().

+ Here is the call graph for this function:

◆ setOpt()

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

Wrapper for curl_setopt.

@access public

Parameters
intCURL_OPTION
mixedbool string or resource
Exceptions
ilCurlConnectionExceptionon error

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

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

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: