ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 
 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.

Reimplemented from CAS_Request_RequestInterface.

Definition at line 86 of file AbstractRequest.php.

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.
if($format !==null) $name
Definition: metadata.php:230

References $name.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 107 of file AbstractRequest.php.

108 {
109 if ($this->_sent) {
111 'Request has already been sent cannot ' . __METHOD__
112 );
113 }
114
115 $this->cookies = array_merge($this->cookies, $cookies);
116 }

References $cookies.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 126 of file AbstractRequest.php.

127 {
128 if ($this->_sent) {
130 'Request has already been sent cannot ' . __METHOD__
131 );
132 }
133
134 $this->headers[] = $header;
135 }

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 145 of file AbstractRequest.php.

146 {
147 if ($this->_sent) {
149 'Request has already been sent cannot ' . __METHOD__
150 );
151 }
152
153 $this->headers = array_merge($this->headers, $headers);
154 }

References $headers.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 369 of file AbstractRequest.php.

370 {
371 if (!$this->_sent) {
373 'Request has not been sent yet. Cannot ' . __METHOD__
374 );
375 }
377 }

References $_errorMessage.

◆ getResponseBody()

CAS_Request_AbstractRequest::getResponseBody ( )

Answer the body of response.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 352 of file AbstractRequest.php.

353 {
354 if (!$this->_sent) {
356 'Request has not been sent yet. Cannot ' . __METHOD__
357 );
358 }
359
361 }

References $_responseBody.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 308 of file AbstractRequest.php.

309 {
310 if (!$this->_sent) {
312 'Request has not been sent yet. Cannot ' . __METHOD__
313 );
314 }
316 }

References $_responseHeaders.

◆ getResponseStatusCode()

CAS_Request_AbstractRequest::getResponseStatusCode ( )

Answer HTTP status code of the response.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 324 of file AbstractRequest.php.

325 {
326 if (!$this->_sent) {
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 }
An Exception for problems performing requests.
Definition: Exception.php:41

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 162 of file AbstractRequest.php.

163 {
164 if ($this->_sent) {
166 'Request has already been sent cannot ' . __METHOD__
167 );
168 }
169
170 $this->isPost = true;
171 }

◆ send()

CAS_Request_AbstractRequest::send ( )

Perform the request.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 227 of file AbstractRequest.php.

228 {
229 if ($this->_sent) {
231 'Request has already been sent cannot send again.'
232 );
233 }
234 if (is_null($this->url) || !$this->url) {
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 }
sendRequest()
Send the request and store the results.

References sendRequest().

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

Reimplemented in CAS_Request_CurlRequest.

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.

Reimplemented from CAS_Request_RequestInterface.

Definition at line 181 of file AbstractRequest.php.

182 {
183 if ($this->_sent) {
185 'Request has already been sent cannot ' . __METHOD__
186 );
187 }
188 if (!$this->isPost) {
190 'Cannot add a POST body to a GET request, use makePost() first.'
191 );
192 }
193
194 $this->postBody = $body;
195 }

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 206 of file AbstractRequest.php.

207 {
208 if ($this->_sent) {
210 'Request has already been sent cannot ' . __METHOD__
211 );
212 }
213 $this->caCertPath = $caCertPath;
214 $this->validateCN = $validate_cn;
215 }

References $caCertPath.

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

Reimplemented from CAS_Request_RequestInterface.

Definition at line 66 of file AbstractRequest.php.

67 {
68 if ($this->_sent) {
70 'Request has already been sent cannot ' . __METHOD__
71 );
72 }
73
74 $this->url = $url;
75 }

References $url.

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

294 {
295 $this->_errorMessage .= $message;
296 }
$message
Definition: xapiexit.php:14

References $message.

Referenced by CAS_Request_CurlRequest\sendRequest().

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

282 {
283 $this->_responseBody = $body;
284 }

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

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

270 {
271 $this->_responseHeaders[] = $header;
272 }

Referenced by CAS_Request_CurlRequest\_curlReadHeaders().

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

References $headers.

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.

Referenced by addCookies().

◆ $headers

CAS_Request_AbstractRequest::$headers = array()
protected

Definition at line 44 of file AbstractRequest.php.

Referenced by addHeaders(), and storeResponseHeaders().

◆ $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: