本文整理汇总了PHP中HttpResponse::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::getStatusCode方法的具体用法?PHP HttpResponse::getStatusCode怎么用?PHP HttpResponse::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::getStatusCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: required
public function required(HttpResponse $response)
{
return HttpConstants::STATUS_AUTHORIZATION_REQUIRED == $response->getStatusCode();
}
示例2: testSetStatusCode
/**
* @covers \http\HttpResponse::setStatusCode
*/
public function testSetStatusCode()
{
$this->object->setStatusCode(301);
$code = $this->object->getStatusCode();
$this->assertEquals(301, $code, 'Status code should be 301');
}
示例3: Test
/** Test Wookie server connection
* @return boolean true if success, otherwise false
*/
public function Test()
{
$ctx = @stream_context_create(array('http' => array('timeout' => 15)));
$url = $this->getURL();
if (!empty($url)) {
$response = new HttpResponse(@file_get_contents($url . 'advertise?all=true', false, $ctx), $http_response_header);
if ($response->getStatusCode() == 200) {
$xmlDoc = @simplexml_load_string($response->getResponseText());
if (is_object($xmlDoc) && $xmlDoc->getName() == 'widgets') {
return true;
}
}
}
return false;
}
示例4: handleErrorResponse
/**
* Handle a non 200 series response from the API.
*
* This method is here specifically for sub-classes to override. When an API call is made and a non-200 series
* status code is returned then this method is called with that response. This lets API client authors to extract
* the appropriate error message out of the response and decide whether or not to throw a PHP exception.
*
* It is recommended that you obey the caller's wishes on whether or not to throw an exception by using the
* following `if` statement:
*
* ```php
* if ($this->val('throw', $options, $this->throwExceptions)) {
* ...
* }
* ```
*
* @param HttpResponse $response The response sent from the API.
* @param array $options The options that were sent with the request.
* @throws \Exception Throws an exception if the settings or options say to throw an exception.
*/
public function handleErrorResponse(HttpResponse $response, $options = [])
{
if ($this->val('throw', $options, $this->throwExceptions)) {
$body = $response->getBody();
if (is_array($body)) {
$message = $this->val('message', $body, $response->getReasonPhrase());
} else {
$message = $response->getReasonPhrase();
}
throw new \Exception($message, $response->getStatusCode());
}
}
示例5: getProperty
/**
* Get property for Widget instance
* @param WidgetInstance instance of WidgetInstance
* @param Propety instance of WidgetProperty
* @return WidgetProperty if request fails, return false;
* @throws WookieConnectorException, WookieWidgetInstanceException
*/
public function getProperty($widgetInstance, $propertyInstance)
{
$Url = $this->getConnection()->getURL() . 'properties';
try {
if (!$widgetInstance instanceof WidgetInstance) {
throw new Exception\WookieWidgetInstanceException('No Widget instance');
}
if (!$propertyInstance instanceof WidgetProperty) {
throw new Exception\WookieConnectorException('No properties instance');
}
$data = array('api_key' => $this->getConnection()->getApiKey(), 'shareddatakey' => $this->getConnection()->getSharedDataKey(), 'userid' => $this->getUser()->getLoginName(), 'widgetid' => $widgetInstance->getIdentifier(), 'propertyname' => $propertyInstance->getName());
$request = @http_build_query($data);
if (!$this->checkURL($Url)) {
throw new Exception\WookieConnectorException("Properties rest URL is incorrect: " . $Url);
}
$response = new HttpResponse(@file_get_contents($Url . '?' . $request, false, $this->getHttpStreamContext()), $http_response_header);
$statusCode = $response->getStatusCode();
if ($statusCode != 200) {
throw new Exception\WookieConnectorException($response->headerToString() . '<br />' . $response->getResponseText());
}
return new WidgetProperty($propertyInstance->getName(), $response->getResponseText());
} catch (WookieConnectorException $e) {
$this->getLogger()->write($e->toString());
} catch (WookieWidgetInstanceException $e) {
$this->getLogger()->write($e->toString());
}
return false;
}