70 $this->_cookieJar = $cookieJar;
87 if (empty($this->_url)) {
89 'No URL set via ' . get_class($this) .
'->setUrl($url).' 112 'Cannot set the URL, request already sent.' 115 if (!is_string(
$url)) {
143 'Cannot send, request already sent.' 152 if (strstr(
$url,
'?') ===
false) {
211 $this->_numRequests++;
212 if ($this->_numRequests > 4) {
213 $message =
'Exceeded the maximum number of redirects (3) in proxied service request.';
223 $request->addCookies($this->_cookieJar->getCookies(
$url));
231 $message =
'Could not perform proxied service request to URL`' 232 .
$url .
'\'.
' . $request->getErrorMessage(); 233 phpCAS::trace($message); 234 throw new CAS_ProxiedService_Exception($message); 237 // Store any cookies from the response; 238 $this->_cookieJar->storeCookies($url, $request->getResponseHeaders()); 240 // Follow any redirects 241 if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders()) 243 phpCAS::trace('Found redirect:
' . $redirectUrl); 244 $this->makeRequest($redirectUrl); 246 $this->_responseHeaders = $request->getResponseHeaders(); 247 $this->_responseBody = $request->getResponseBody(); 248 $this->_responseStatusCode = $request->getResponseStatusCode(); 259 abstract protected function populateRequest( 260 CAS_Request_RequestInterface $request 270 protected function getRedirectUrl(array $responseHeaders) 272 // Check for the redirect after authentication 273 foreach ($responseHeaders as $header) { 274 if (preg_match('/^(Location:|URI:)\
s*([^\
s]+.*)$/
', $header, $matches) 276 return trim(array_pop($matches)); 282 /********************************************************* 283 * 3. Access the response 284 *********************************************************/ 291 protected function hasBeenSent() 293 return ($this->_numRequests > 0); 302 public function getResponseHeaders() 304 if (!$this->hasBeenSent()) { 305 throw new CAS_OutOfSequenceException( 306 'Cannot access response, request not sent yet.
' 310 return $this->_responseHeaders; 319 public function getResponseStatusCode() 321 if (!$this->hasBeenSent()) { 322 throw new CAS_OutOfSequenceException( 323 'Cannot access response, request not sent yet.
' 327 return $this->_responseStatusCode; 336 public function getResponseBody() 338 if (!$this->hasBeenSent()) { 339 throw new CAS_OutOfSequenceException( 340 'Cannot access response, request not sent yet.
' 344 return $this->_responseBody; 353 public function getCookies() 355 return $this->_cookieJar->getCookies($this->getServiceUrl()); $_url
The target service url.
foreach($paths as $path) $request
initializeProxyTicket()
Fetch our proxy ticket.
send()
Perform the request.
$_numRequests
Indicator of the number of requests (including redirects performed.
getServiceUrl()
Answer a service identifier (URL) for whom we should fetch a proxy ticket.
An Exception for problems communicating with a proxied service.
This interface defines a class library for performing web requests.
This class implements common methods for ProxiedService implementations included with phpCAS...
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
static trace($str)
This method is used to log something in debug mode.
makeRequest($url)
Build and perform a request, following redirects.
$requestHandler
The HTTP request mechanism talking to the target service.
catch(Exception $e) $message
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
hasBeenSent()
Answer true if our request has been sent yet.
Exception that denotes invalid arguments were passed.
$_responseHeaders
The response headers.
This interface defines methods that clients should use for configuring, sending, and receiving proxie...
__construct(CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar)
Constructor.
This class implements common methods for ProxiedService implementations included with phpCAS...
setUrl($url)
Set the URL of the Request.
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
getProxyTicket()
Answer the proxy ticket to be used when making requests.
$_responseBody
The response headers.
$_responseStatusCode
The response status code.
populateRequest(CAS_Request_RequestInterface $request)
Add any other parts of the request needed by concrete classes.
$_cookieJar
The storage mechanism for cookies set by the target service.
This class provides access to service cookies and handles parsing of response headers to pull out coo...