ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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...
 
 getInfo ($opt=0)
 Get informations about a specific transfer. More...
 
 close ()
 Close connection. More...
 
 __destruct ()
 Destructor. 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()
 

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

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

◆ __destruct()

ilCurlConnection::__destruct ( )

Destructor.

@access public

Parameters

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

234 {
235 $this->close();
236 }
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 71 of file class.ilCurlConnection.php.

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

Referenced by ilMediaImageUtil\getImageSize().

+ Here is the caller graph for this function:

◆ close()

ilCurlConnection::close ( )
final

Close connection.

@access public

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

218 {
219 if($this->ch != null)
220 {
221 curl_close($this->ch);
222 $this->ch = null;
223 }
224 }

Referenced by __destruct().

+ Here is the caller graph for this function:

◆ exec()

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

@access public

Parameters

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

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

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

180 {
181 if($opt)
182 {
183 $res = curl_getinfo($this->ch, $opt);
184 }
185 else
186 {
187 $res = curl_getinfo($this->ch);
188 }
189 return $res;
190 }

References $res.

◆ 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 if(strlen($this->url))
108 {
109 $this->ch = curl_init($this->url);
110 #$GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->url);
111 }
112 else
113 {
114 $this->ch = curl_init();
115 }
116 if(!$this->ch)
117 {
118 throw new ilCurlConnectionException('Cannot init curl connection.');
119 }
120 if(curl_errno($this->ch))
121 {
122 throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
123 }
124
125 return true;
126 }

◆ parseHeader()

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.

199 {
200 $this->header_plain = $header;
201
202 $lines = explode('\r\n',$this->getResponseHeader());
203 foreach($lines as $line)
204 {
205 list($name,$value) = explode(':',$line,2);
206 $this->header_arr[$name] = $value;
207 }
208 return strlen($this->getResponseHeader());
209 }
getResponseHeader()
Get response header as string.
$header

References $header, and getResponseHeader().

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

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

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

◆ $url

ilCurlConnection::$url = ''
protected

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


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