ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CAS_Request_CurlRequest Class Reference

Provides support for performing web-requests via curl. More...

+ Inheritance diagram for CAS_Request_CurlRequest:
+ Collaboration diagram for CAS_Request_CurlRequest:

Public Member Functions

 setCurlOptions (array $options)
 Set additional curl options. More...
 
 initAndConfigure ()
 Internal method to initialize our cURL handle and configure the request. More...
 
- Public Member Functions inherited from CAS_Request_AbstractRequest
 setUrl ($url)
 Set the URL of the Request. More...
 
 addCookie ($name, $value)
 Add a cookie to the request. More...
 
 addCookies (array $cookies)
 Add an array of cookies to the request. More...
 
 addHeader ($header)
 Add a header string to the request. More...
 
 addHeaders (array $headers)
 Add an array of header strings to the request. More...
 
 makePost ()
 Make the request a POST request rather than the default GET request. More...
 
 setPostBody ($body)
 Add a POST body to the request. More...
 
 setSslCaCert ($caCertPath, $validate_cn=true)
 Specify the path to an SSL CA certificate to validate the server with. More...
 
 send ()
 Perform the request. More...
 
 getResponseHeaders ()
 Answer the headers of the response. More...
 
 getResponseStatusCode ()
 Answer HTTP status code of the response. More...
 
 getResponseBody ()
 Answer the body of response. More...
 
 getErrorMessage ()
 Answer a message describing any errors if the request failed. More...
 
- Public Member Functions inherited from CAS_Request_RequestInterface
 setUrl ($url)
 Set the URL of the Request. More...
 
 addCookie ($name, $value)
 Add a cookie to the request. More...
 
 addCookies (array $cookies)
 Add an array of cookies to the request. More...
 
 addHeader ($header)
 Add a header string to the request. More...
 
 addHeaders (array $headers)
 Add an array of header strings to the request. More...
 
 makePost ()
 Make the request a POST request rather than the default GET request. More...
 
 setPostBody ($body)
 Add a POST body to the request. More...
 
 setSslCaCert ($caCertPath, $validate_cn=true)
 Specify the path to an SSL CA certificate to validate the server with. More...
 
 send ()
 Perform the request. More...
 
 getResponseHeaders ()
 Answer the headers of the response. More...
 
 getResponseStatusCode ()
 Answer HTTP status code of the response. More...
 
 getResponseBody ()
 Answer the body of response. More...
 
 getErrorMessage ()
 Answer a message describing any errors if the request failed. More...
 

Protected Member Functions

 sendRequest ()
 Send the request and store the results. More...
 
- Protected Member Functions inherited from CAS_Request_AbstractRequest
 sendRequest ()
 Send the request and store the results. More...
 
 storeResponseHeaders (array $headers)
 Store the response headers. More...
 
 storeResponseHeader ($header)
 Store a single response header to our array. More...
 
 storeResponseBody ($body)
 Store the response body. More...
 
 storeErrorMessage ($message)
 Add a string to our error message. More...
 

Private Member Functions

 _storeResponseBody ($body)
 Store the response body. More...
 
 _curlReadHeaders ($ch, $header)
 Internal method for capturing the headers from a curl request. More...
 

Private Attributes

 $_curlOptions = array()
 

Additional Inherited Members

- Protected Attributes inherited from CAS_Request_AbstractRequest
 $url = null
 
 $cookies = array()
 
 $headers = array()
 
 $isPost = false
 
 $postBody = null
 
 $caCertPath = null
 
 $validateCN = true
 

Detailed Description

Provides support for performing web-requests via curl.

Definition at line 40 of file CurlRequest.php.

Member Function Documentation

◆ _curlReadHeaders()

CAS_Request_CurlRequest::_curlReadHeaders (   $ch,
  $header 
)
private

Internal method for capturing the headers from a curl request.

Parameters
handle$chhandle of curl
string$headerheader
Returns
void

Definition at line 192 of file CurlRequest.php.

References $header, and CAS_Request_AbstractRequest\storeResponseHeader().

193  {
195  return strlen($header);
196  }
storeResponseHeader($header)
Store a single response header to our array.
+ Here is the call graph for this function:

◆ _storeResponseBody()

CAS_Request_CurlRequest::_storeResponseBody (   $body)
private

Store the response body.

This method should NOT be used outside of the CurlRequest or the CurlMultiRequest.

Parameters
string$bodybody to stor
Returns
void

Definition at line 179 of file CurlRequest.php.

References CAS_Request_AbstractRequest\storeResponseBody().

180  {
181  $this->storeResponseBody($body);
182  }
storeResponseBody($body)
Store the response body.
+ Here is the call graph for this function:

◆ initAndConfigure()

CAS_Request_CurlRequest::initAndConfigure ( )

Internal method to initialize our cURL handle and configure the request.

This method should NOT be used outside of the CurlRequest or the CurlMultiRequest.

Returns
resource The cURL handle on success, false on failure

Definition at line 99 of file CurlRequest.php.

References $key, $name, and phpCAS\trace().

Referenced by sendRequest().

100  {
101  /*********************************************************
102  * initialize the CURL session
103  *********************************************************/
104  $ch = curl_init($this->url);
105 
106  if (version_compare(PHP_VERSION, '5.1.3', '>=')) {
107  //only avaible in php5
108  curl_setopt_array($ch, $this->_curlOptions);
109  } else {
110  foreach ($this->_curlOptions as $key => $value) {
111  curl_setopt($ch, $key, $value);
112  }
113  }
114 
115  /*********************************************************
116  * Set SSL configuration
117  *********************************************************/
118  if ($this->caCertPath) {
119  if ($this->validateCN) {
120  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
121  } else {
122  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
123  }
124  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
125  curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath);
126  phpCAS::trace('CURL: Set CURLOPT_CAINFO ' . $this->caCertPath);
127  } else {
128  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
129  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
130  }
131 
132  /*********************************************************
133  * Configure curl to capture our output.
134  *********************************************************/
135  // return the CURL output into a variable
136  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
137 
138  // get the HTTP header with a callback
139  curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders'));
140 
141  /*********************************************************
142  * Add cookie headers to our request.
143  *********************************************************/
144  if (count($this->cookies)) {
145  $cookieStrings = array();
146  foreach ($this->cookies as $name => $val) {
147  $cookieStrings[] = $name . '=' . $val;
148  }
149  curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings));
150  }
151 
152  /*********************************************************
153  * Add any additional headers
154  *********************************************************/
155  if (count($this->headers)) {
156  curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
157  }
158 
159  /*********************************************************
160  * Flag and Body for POST requests
161  *********************************************************/
162  if ($this->isPost) {
163  curl_setopt($ch, CURLOPT_POST, 1);
164  curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody);
165  }
166 
167  return $ch;
168  }
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:599
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendRequest()

CAS_Request_CurlRequest::sendRequest ( )
protected

Send the request and store the results.

Returns
bool true on success, false on failure.

Definition at line 61 of file CurlRequest.php.

References $res, initAndConfigure(), CAS_Request_AbstractRequest\storeErrorMessage(), CAS_Request_AbstractRequest\storeResponseBody(), phpCAS\trace(), phpCAS\traceBegin(), and phpCAS\traceEnd().

62  {
64 
65  /*********************************************************
66  * initialize the CURL session
67  *********************************************************/
68  $ch = $this->initAndConfigure();
69 
70  /*********************************************************
71  * Perform the query
72  *********************************************************/
73  $buf = curl_exec($ch);
74  if ($buf === false) {
75  phpCAS::trace('curl_exec() failed');
76  $this->storeErrorMessage(
77  'CURL error #' . curl_errno($ch) . ': ' . curl_error($ch)
78  );
79  $res = false;
80  } else {
81  $this->storeResponseBody($buf);
82  phpCAS::trace("Response Body: \n" . $buf . "\n");
83  $res = true;
84  }
85  // close the CURL session
86  curl_close($ch);
87 
89  return $res;
90  }
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:599
foreach($_POST as $key=> $value) $res
storeErrorMessage($message)
Add a string to our error message.
initAndConfigure()
Internal method to initialize our cURL handle and configure the request.
Definition: CurlRequest.php:99
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
storeResponseBody($body)
Store the response body.
+ Here is the call graph for this function:

◆ setCurlOptions()

CAS_Request_CurlRequest::setCurlOptions ( array  $options)

Set additional curl options.

Parameters
array$optionsoption to set
Returns
void

Definition at line 50 of file CurlRequest.php.

References PHPMailer\PHPMailer\$options.

51  {
52  $this->_curlOptions = $options;
53  }

Field Documentation

◆ $_curlOptions

CAS_Request_CurlRequest::$_curlOptions = array()
private

Definition at line 54 of file CurlRequest.php.


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