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

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

+ Inheritance diagram for CAS_Request_AbstractRequest:
+ Collaboration diagram for CAS_Request_AbstractRequest:

Public Member Functions

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

Protected Attributes

 $url = null
 
 $cookies = array()
 
 $headers = array()
 
 $isPost = false
 
 $postBody = null
 
 $caCertPath = null
 
 $validateCN = true
 

Private Attributes

 $_sent = false
 
 $_responseHeaders = array()
 
 $_responseBody = null
 
 $_errorMessage = ''
 

Detailed Description

Provides support for performing web-requests via curl.

Definition at line 40 of file AbstractRequest.php.

Member Function Documentation

◆ addCookie()

CAS_Request_AbstractRequest::addCookie (   $name,
  $value 
)

Add a cookie to the request.

Parameters
string$nameName of entry
string$valuevalue of entry
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 86 of file AbstractRequest.php.

References $name.

87  {
88  if ($this->_sent) {
90  'Request has already been sent cannot ' . __METHOD__
91  );
92  }
93 
94  $this->cookies[$name] = $value;
95  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ addCookies()

CAS_Request_AbstractRequest::addCookies ( array  $cookies)

Add an array of cookies to the request.

The cookie array is of the form array('cookie_name' => 'cookie_value', 'cookie_name2' => cookie_value2')

Parameters
array$cookiescookies to add
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 107 of file AbstractRequest.php.

108  {
109  if ($this->_sent) {
110  throw new CAS_OutOfSequenceException(
111  'Request has already been sent cannot ' . __METHOD__
112  );
113  }
114 
115  $this->cookies = array_merge($this->cookies, $cookies);
116  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ addHeader()

CAS_Request_AbstractRequest::addHeader (   $header)

Add a header string to the request.

Parameters
string$headerHeader to add
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 126 of file AbstractRequest.php.

References $header.

127  {
128  if ($this->_sent) {
129  throw new CAS_OutOfSequenceException(
130  'Request has already been sent cannot ' . __METHOD__
131  );
132  }
133 
134  $this->headers[] = $header;
135  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ addHeaders()

CAS_Request_AbstractRequest::addHeaders ( array  $headers)

Add an array of header strings to the request.

Parameters
array$headersheaders to add
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 145 of file AbstractRequest.php.

146  {
147  if ($this->_sent) {
148  throw new CAS_OutOfSequenceException(
149  'Request has already been sent cannot ' . __METHOD__
150  );
151  }
152 
153  $this->headers = array_merge($this->headers, $headers);
154  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ getErrorMessage()

CAS_Request_AbstractRequest::getErrorMessage ( )

Answer a message describing any errors if the request failed.

Returns
string
Exceptions
CAS_OutOfSequenceExceptionIf called before the Request has been sent.

Definition at line 369 of file AbstractRequest.php.

References $_errorMessage.

370  {
371  if (!$this->_sent) {
372  throw new CAS_OutOfSequenceException(
373  'Request has not been sent yet. Cannot ' . __METHOD__
374  );
375  }
376  return $this->_errorMessage;
377  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ getResponseBody()

CAS_Request_AbstractRequest::getResponseBody ( )

Answer the body of response.

Returns
string
Exceptions
CAS_OutOfSequenceExceptionIf called before the Request has been sent.

Definition at line 352 of file AbstractRequest.php.

References $_responseBody.

353  {
354  if (!$this->_sent) {
355  throw new CAS_OutOfSequenceException(
356  'Request has not been sent yet. Cannot ' . __METHOD__
357  );
358  }
359 
360  return $this->_responseBody;
361  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ getResponseHeaders()

CAS_Request_AbstractRequest::getResponseHeaders ( )

Answer the headers of the response.

Returns
array An array of header strings.
Exceptions
CAS_OutOfSequenceExceptionIf called before the Request has been sent.

Definition at line 308 of file AbstractRequest.php.

References $_responseHeaders.

309  {
310  if (!$this->_sent) {
311  throw new CAS_OutOfSequenceException(
312  'Request has not been sent yet. Cannot ' . __METHOD__
313  );
314  }
316  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ getResponseStatusCode()

CAS_Request_AbstractRequest::getResponseStatusCode ( )

Answer HTTP status code of the response.

Returns
int
Exceptions
CAS_OutOfSequenceExceptionIf called before the Request has been sent.

Definition at line 324 of file AbstractRequest.php.

325  {
326  if (!$this->_sent) {
327  throw new CAS_OutOfSequenceException(
328  'Request has not been sent yet. Cannot ' . __METHOD__
329  );
330  }
331 
332  if (!preg_match(
333  '/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
334  $this->_responseHeaders[0],
335  $matches
336  )
337  ) {
338  throw new CAS_Request_Exception(
339  'Bad response, no status code was found in the first line.'
340  );
341  }
342 
343  return intval($matches[1]);
344  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
An Exception for problems performing requests.
Definition: Exception.php:40

◆ makePost()

CAS_Request_AbstractRequest::makePost ( )

Make the request a POST request rather than the default GET request.

Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 162 of file AbstractRequest.php.

163  {
164  if ($this->_sent) {
165  throw new CAS_OutOfSequenceException(
166  'Request has already been sent cannot ' . __METHOD__
167  );
168  }
169 
170  $this->isPost = true;
171  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ send()

CAS_Request_AbstractRequest::send ( )

Perform the request.

Returns
bool TRUE on success, FALSE on failure.
Exceptions
CAS_OutOfSequenceExceptionIf called multiple times.

Definition at line 227 of file AbstractRequest.php.

References sendRequest().

228  {
229  if ($this->_sent) {
230  throw new CAS_OutOfSequenceException(
231  'Request has already been sent cannot send again.'
232  );
233  }
234  if (is_null($this->url) || !$this->url) {
235  throw new CAS_OutOfSequenceException(
236  'A url must be specified via setUrl() before the request can be sent.'
237  );
238  }
239  $this->_sent = true;
240  return $this->sendRequest();
241  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
sendRequest()
Send the request and store the results.
+ Here is the call graph for this function:

◆ sendRequest()

CAS_Request_AbstractRequest::sendRequest ( )
abstractprotected

Send the request and store the results.

Returns
bool TRUE on success, FALSE on failure.

Referenced by send().

+ Here is the caller graph for this function:

◆ setPostBody()

CAS_Request_AbstractRequest::setPostBody (   $body)

Add a POST body to the request.

Parameters
string$bodybody to add
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 181 of file AbstractRequest.php.

182  {
183  if ($this->_sent) {
184  throw new CAS_OutOfSequenceException(
185  'Request has already been sent cannot ' . __METHOD__
186  );
187  }
188  if (!$this->isPost) {
189  throw new CAS_OutOfSequenceException(
190  'Cannot add a POST body to a GET request, use makePost() first.'
191  );
192  }
193 
194  $this->postBody = $body;
195  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ setSslCaCert()

CAS_Request_AbstractRequest::setSslCaCert (   $caCertPath,
  $validate_cn = true 
)

Specify the path to an SSL CA certificate to validate the server with.

Parameters
string$caCertPathpath to cert
bool$validate_cnvaldiate CN of certificate
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 206 of file AbstractRequest.php.

References $caCertPath.

207  {
208  if ($this->_sent) {
209  throw new CAS_OutOfSequenceException(
210  'Request has already been sent cannot ' . __METHOD__
211  );
212  }
213  $this->caCertPath = $caCertPath;
214  $this->validateCN = $validate_cn;
215  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ setUrl()

CAS_Request_AbstractRequest::setUrl (   $url)

Set the URL of the Request.

Parameters
string$urlUrl to set
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the Request has been sent.

Definition at line 66 of file AbstractRequest.php.

References $url.

67  {
68  if ($this->_sent) {
70  'Request has already been sent cannot ' . __METHOD__
71  );
72  }
73 
74  $this->url = $url;
75  }
This class defines Exceptions that should be thrown when the sequence of operations is invalid...

◆ storeErrorMessage()

CAS_Request_AbstractRequest::storeErrorMessage (   $message)
protected

Add a string to our error message.

Parameters
string$messagemessage to add
Returns
void

Definition at line 293 of file AbstractRequest.php.

References $message.

Referenced by CAS_Request_CurlRequest\sendRequest().

294  {
295  $this->_errorMessage .= $message;
296  }
catch(Exception $e) $message
+ Here is the caller graph for this function:

◆ storeResponseBody()

CAS_Request_AbstractRequest::storeResponseBody (   $body)
protected

Store the response body.

Parameters
string$bodybody to store
Returns
void

Definition at line 281 of file AbstractRequest.php.

Referenced by CAS_Request_CurlRequest\_storeResponseBody(), and CAS_Request_CurlRequest\sendRequest().

282  {
283  $this->_responseBody = $body;
284  }
+ Here is the caller graph for this function:

◆ storeResponseHeader()

CAS_Request_AbstractRequest::storeResponseHeader (   $header)
protected

Store a single response header to our array.

Parameters
string$headerheader to store
Returns
void

Definition at line 269 of file AbstractRequest.php.

References $header.

Referenced by CAS_Request_CurlRequest\_curlReadHeaders().

270  {
271  $this->_responseHeaders[] = $header;
272  }
+ Here is the caller graph for this function:

◆ storeResponseHeaders()

CAS_Request_AbstractRequest::storeResponseHeaders ( array  $headers)
protected

Store the response headers.

Parameters
array$headersheaders to store
Returns
void

Definition at line 257 of file AbstractRequest.php.

258  {
259  $this->_responseHeaders = array_merge($this->_responseHeaders, $headers);
260  }

Field Documentation

◆ $_errorMessage

CAS_Request_AbstractRequest::$_errorMessage = ''
private

Definition at line 52 of file AbstractRequest.php.

Referenced by getErrorMessage().

◆ $_responseBody

CAS_Request_AbstractRequest::$_responseBody = null
private

Definition at line 51 of file AbstractRequest.php.

Referenced by getResponseBody().

◆ $_responseHeaders

CAS_Request_AbstractRequest::$_responseHeaders = array()
private

Definition at line 50 of file AbstractRequest.php.

Referenced by getResponseHeaders().

◆ $_sent

CAS_Request_AbstractRequest::$_sent = false
private

Definition at line 49 of file AbstractRequest.php.

◆ $caCertPath

CAS_Request_AbstractRequest::$caCertPath = null
protected

Definition at line 47 of file AbstractRequest.php.

Referenced by setSslCaCert().

◆ $cookies

CAS_Request_AbstractRequest::$cookies = array()
protected

Definition at line 43 of file AbstractRequest.php.

◆ $headers

CAS_Request_AbstractRequest::$headers = array()
protected

Definition at line 44 of file AbstractRequest.php.

◆ $isPost

CAS_Request_AbstractRequest::$isPost = false
protected

Definition at line 45 of file AbstractRequest.php.

◆ $postBody

CAS_Request_AbstractRequest::$postBody = null
protected

Definition at line 46 of file AbstractRequest.php.

◆ $url

CAS_Request_AbstractRequest::$url = null
protected

Definition at line 42 of file AbstractRequest.php.

Referenced by setUrl().

◆ $validateCN

CAS_Request_AbstractRequest::$validateCN = true
protected

Definition at line 48 of file AbstractRequest.php.


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