CAS_Client::serviceWeb PHP Method

serviceWeb() public method

This method is used to access an HTTP[S] service.
public serviceWeb ( string $url, &$err_code, &$output ) : true
$url string the service to access.
return true on success, false otherwise (in this later case, $err_code gives the reason why it failed and $output contains an error message).
    public function serviceWeb($url, &$err_code, &$output)
    {
        // Sequence validation
        $this->ensureIsProxy();
        $this->ensureAuthenticationCallSuccessful();
        // Argument validation
        if (gettype($url) != 'string') {
            throw new CAS_TypeMismatchException($url, '$url', 'string');
        }
        try {
            $service = $this->getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
            $service->setUrl($url);
            $service->send();
            $output = $service->getResponseBody();
            $err_code = PHPCAS_SERVICE_OK;
            return true;
        } catch (CAS_ProxyTicketException $e) {
            $err_code = $e->getCode();
            $output = $e->getMessage();
            return false;
        } catch (CAS_ProxiedService_Exception $e) {
            $lang = $this->getLangObj();
            $output = sprintf($lang->getServiceUnavailable(), $url, $e->getMessage());
            $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
            return false;
        }
    }

Usage Example

示例#1
0
 /**
  * Verify that proxied-service Exceptions are caught and converted to error
  * codes in serviceWeb().
  *
  * @return void
  */
 public function testServiceWebServiceError()
 {
     $result = $this->object->serviceWeb('ssh://me.example.net', $err_code, $output);
     $this->assertFalse($result, "serviceWeb() should have returned false on a service error.");
     $this->assertEquals(PHPCAS_SERVICE_NOT_AVAILABLE, $err_code);
     $this->assertStringStartsWith("The service", $output);
 }
All Usage Examples Of CAS_Client::serviceWeb
CAS_Client