ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 88 of file AbstractRequest.php.

References $name.

89  {
90  if ($this->_sent) {
92  'Request has already been sent cannot '.__METHOD__
93  );
94  }
95 
96  $this->cookies[$name] = $value;
97  }
if($format !==null) $name
Definition: metadata.php:146
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 109 of file AbstractRequest.php.

110  {
111  if ($this->_sent) {
112  throw new CAS_OutOfSequenceException(
113  'Request has already been sent cannot '.__METHOD__
114  );
115  }
116 
117  $this->cookies = array_merge($this->cookies, $cookies);
118  }
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 128 of file AbstractRequest.php.

References $header.

129  {
130  if ($this->_sent) {
131  throw new CAS_OutOfSequenceException(
132  'Request has already been sent cannot '.__METHOD__
133  );
134  }
135 
136  $this->headers[] = $header;
137  }
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 147 of file AbstractRequest.php.

148  {
149  if ($this->_sent) {
150  throw new CAS_OutOfSequenceException(
151  'Request has already been sent cannot '.__METHOD__
152  );
153  }
154 
155  $this->headers = array_merge($this->headers, $headers);
156  }
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 370 of file AbstractRequest.php.

References $_errorMessage.

371  {
372  if (!$this->_sent) {
373  throw new CAS_OutOfSequenceException(
374  'Request has not been sent yet. Cannot '.__METHOD__
375  );
376  }
377  return $this->_errorMessage;
378  }
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 353 of file AbstractRequest.php.

References $_responseBody.

354  {
355  if (!$this->_sent) {
356  throw new CAS_OutOfSequenceException(
357  'Request has not been sent yet. Cannot '.__METHOD__
358  );
359  }
360 
361  return $this->_responseBody;
362  }
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 310 of file AbstractRequest.php.

References $_responseHeaders.

311  {
312  if (!$this->_sent) {
313  throw new CAS_OutOfSequenceException(
314  'Request has not been sent yet. Cannot '.__METHOD__
315  );
316  }
318  }
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 326 of file AbstractRequest.php.

327  {
328  if (!$this->_sent) {
329  throw new CAS_OutOfSequenceException(
330  'Request has not been sent yet. Cannot '.__METHOD__
331  );
332  }
333 
334  if (!preg_match(
335  '/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
336  $this->_responseHeaders[0], $matches
337  )
338  ) {
339  throw new CAS_Request_Exception(
340  'Bad response, no status code was found in the first line.'
341  );
342  }
343 
344  return intval($matches[1]);
345  }
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 164 of file AbstractRequest.php.

165  {
166  if ($this->_sent) {
167  throw new CAS_OutOfSequenceException(
168  'Request has already been sent cannot '.__METHOD__
169  );
170  }
171 
172  $this->isPost = true;
173  }
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 229 of file AbstractRequest.php.

References sendRequest().

230  {
231  if ($this->_sent) {
232  throw new CAS_OutOfSequenceException(
233  'Request has already been sent cannot send again.'
234  );
235  }
236  if (is_null($this->url) || !$this->url) {
237  throw new CAS_OutOfSequenceException(
238  'A url must be specified via setUrl() before the request can be sent.'
239  );
240  }
241  $this->_sent = true;
242  return $this->sendRequest();
243  }
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 183 of file AbstractRequest.php.

184  {
185  if ($this->_sent) {
186  throw new CAS_OutOfSequenceException(
187  'Request has already been sent cannot '.__METHOD__
188  );
189  }
190  if (!$this->isPost) {
191  throw new CAS_OutOfSequenceException(
192  'Cannot add a POST body to a GET request, use makePost() first.'
193  );
194  }
195 
196  $this->postBody = $body;
197  }
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 208 of file AbstractRequest.php.

References $caCertPath.

209  {
210  if ($this->_sent) {
211  throw new CAS_OutOfSequenceException(
212  'Request has already been sent cannot '.__METHOD__
213  );
214  }
215  $this->caCertPath = $caCertPath;
216  $this->validateCN = $validate_cn;
217  }
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 68 of file AbstractRequest.php.

References $url.

69  {
70  if ($this->_sent) {
72  'Request has already been sent cannot '.__METHOD__
73  );
74  }
75 
76  $this->url = $url;
77  }
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 295 of file AbstractRequest.php.

References $message.

Referenced by CAS_Request_CurlRequest\sendRequest().

296  {
297  $this->_errorMessage .= $message;
298  }
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 283 of file AbstractRequest.php.

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

284  {
285  $this->_responseBody = $body;
286  }
+ 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 271 of file AbstractRequest.php.

References $header.

Referenced by CAS_Request_CurlRequest\_curlReadHeaders().

272  {
273  $this->_responseHeaders[] = $header;
274  }
+ 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 259 of file AbstractRequest.php.

260  {
261  $this->_responseHeaders = array_merge($this->_responseHeaders, $headers);
262  }

Field Documentation

◆ $_errorMessage

CAS_Request_AbstractRequest::$_errorMessage = ''
private

Definition at line 54 of file AbstractRequest.php.

Referenced by getErrorMessage().

◆ $_responseBody

CAS_Request_AbstractRequest::$_responseBody = null
private

Definition at line 53 of file AbstractRequest.php.

Referenced by getResponseBody().

◆ $_responseHeaders

CAS_Request_AbstractRequest::$_responseHeaders = array()
private

Definition at line 52 of file AbstractRequest.php.

Referenced by getResponseHeaders().

◆ $_sent

CAS_Request_AbstractRequest::$_sent = false
private

Definition at line 51 of file AbstractRequest.php.

◆ $caCertPath

CAS_Request_AbstractRequest::$caCertPath = null
protected

Definition at line 49 of file AbstractRequest.php.

Referenced by setSslCaCert().

◆ $cookies

CAS_Request_AbstractRequest::$cookies = array()
protected

Definition at line 45 of file AbstractRequest.php.

◆ $headers

CAS_Request_AbstractRequest::$headers = array()
protected

Definition at line 46 of file AbstractRequest.php.

◆ $isPost

CAS_Request_AbstractRequest::$isPost = false
protected

Definition at line 47 of file AbstractRequest.php.

◆ $postBody

CAS_Request_AbstractRequest::$postBody = null
protected

Definition at line 48 of file AbstractRequest.php.

◆ $url

CAS_Request_AbstractRequest::$url = null
protected

Definition at line 44 of file AbstractRequest.php.

Referenced by setUrl().

◆ $validateCN

CAS_Request_AbstractRequest::$validateCN = true
protected

Definition at line 50 of file AbstractRequest.php.


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