本文整理汇总了PHP中Zend_Http_Response::responseCodeAsText方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Response::responseCodeAsText方法的具体用法?PHP Zend_Http_Response::responseCodeAsText怎么用?PHP Zend_Http_Response::responseCodeAsText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Response
的用法示例。
在下文中一共展示了Zend_Http_Response::responseCodeAsText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: errorAction
/**
* Handle all API errors.
*/
public function errorAction()
{
$data = array();
$exception = $this->_getParam('error_handler')->exception;
// Add code and message to response.
$code = $exception->getCode();
if (!$code) {
$code = self::DEFAULT_HTTP_RESPONSE_CODE;
}
$message = $exception->getMessage();
if (!$message) {
$message = Zend_Http_Response::responseCodeAsText($code);
}
$data['message'] = $message;
// Add errors to response.
if ($exception instanceof Omeka_Controller_Exception_Api) {
if ($errors = $exception->getErrors()) {
$data['errors'] = $errors;
}
}
try {
$this->getResponse()->setHttpResponseCode($code);
} catch (Zend_Controller_Exception $e) {
// The response code was invalid. Set the default.
$this->getResponse()->setHttpResponseCode(self::DEFAULT_HTTP_RESPONSE_CODE);
}
$this->_helper->json($data);
}
示例2: _doRequest
/**
* Make a HTTP request.
* @param string $method
* @param array $getParameters
* @param array $postParameters
* @throws Insulin_Service_Rest_ConnectionFailedException
* @throws Insulin_Service_Rest_HttpErrorException
*/
protected function _doRequest($method, array $getParameters = null, array $postParameters = null)
{
$link = $this->getLink();
if (!empty($postParameters)) {
$link->setParameterPost($postParameters);
}
if (!empty($getParameters)) {
$link->setParameterGet($getParameters);
}
$link->setUri($this->_endpoint);
$link->setMethod($method);
require_once 'Zend/Http/Exception.php';
try {
$response = $link->request();
} catch (Zend_Http_Exception $e) {
require_once 'Insulin/Service/Rest/ConnectionFailedException.php';
throw new Insulin_Service_Rest_ConnectionFailedException();
}
if ($response->isError()) {
require_once 'Insulin/Service/Rest/HttpErrorException.php';
// extract error code from response
$code = Zend_Http_Response::extractCode($response);
// extract standard error message from response
$msg = Zend_Http_Response::responseCodeAsText($code);
throw new Insulin_Service_Rest_HttpErrorException($code, $msg);
}
return $response;
}
示例3: __construct
public function __construct($statusCode, $isFlexClient = false)
{
$this->_isFlexClient = $isFlexClient;
$this->_realStatusCode = $statusCode;
if ($this->_isFlexClient == true) {
$this->_statusCode = 200;
$this->_statusMessage = Zend_Http_Response::responseCodeAsText($this->_realStatusCode);
parent::__construct(200, $_SERVER);
header("HTTP/1.1 200 OK");
} else {
$this->_statusCode = $statusCode;
$this->_statusMessage = Zend_Http_Response::responseCodeAsText($statusCode);
parent::__construct($statusCode, $_SERVER);
header("HTTP/1.1 {$statusCode} " . $this->_statusMessage);
}
}
示例4: testUnknownCode
public function testUnknownCode()
{
$response_str = $this->readResponse('response_unknown');
$response = Zend_Http_Response::fromString($response_str);
// Check that dynamically the message is parsed
$this->assertEquals(550, $response->getStatus(), 'Status is expected to be a non-standard 550');
$this->assertEquals('Printer On Fire', $response->getMessage(), 'Message is expected to be extracted');
// Check that statically, an Unknown string is returned for the 550 code
$this->assertEquals('Unknown', Zend_Http_Response::responseCodeAsText($response_str));
}
示例5: fetch
/** Send a request to the server.
*
* @param string $method
* @param string $path
* @param array $params
*
* @return string server response.
*/
public function fetch($method, $path, array $params = array())
{
$key = $this->_genContentKey($path, $params);
if (isset($this->_content[$method][$key])) {
list($content, $status) = $this->_content[$method][$key];
} elseif (isset($this->_content[self::METHOD_ANY][$key])) {
list($content, $status) = $this->_content[self::METHOD_ANY][$key];
} else {
$status = self::STATUS_NOT_FOUND;
$content = Zend_Http_Response::responseCodeAsText(self::STATUS_NOT_FOUND);
}
$this->_requests[] = $key;
return new JsonApi_Http_Response($this->getUri($path, $params, $method), $status, $content);
}
示例6: responseCodeAsText
/**
* Maps HTTP status code to correct HTTP response text.
*/
public function responseCodeAsText()
{
require_once 'Zend/Http/Response.php';
return Zend_Http_Response::responseCodeAsText($this->code);
}
示例7: _apiRequest
/**
* Applies the search filter and makes the actual API request
*
* @param array $searchFilter
* @return string
*/
private function _apiRequest(array $searchFilter)
{
$this->_setSearchFilter($searchFilter);
$serviceUri = $this->_apiEndpoint . ".{$this->_responseFormat}";
$client = new Zend_Http_Client($serviceUri);
$client->setParameterGet(array('key' => $this->_apiKey));
foreach ($this->_searchFilter as $key => $value) {
if ($key === 'url') {
$key = 'q';
}
$client->setParameterGet(array($key => $value));
}
$response = $client->request();
if (403 === Zend_Http_Response::extractCode($response)) {
$codeAsText = strtolower(Zend_Http_Response::responseCodeAsText(403));
throw new Exception("Access to Backtweets API {$codeAsText}, check used API key");
}
return $response->getBody();
}
示例8: failureDescription
/** Appends relevant error message information to a failed status check.
*
* @param Test_Browser $browser
*
* @return string
*/
protected function failureDescription($browser)
{
$code = $browser->getResponse()->getStatusCode();
/* See if there's an error we can report. */
if (!($error = (string) $browser->getError())) {
$error = Zend_Http_Response::responseCodeAsText($code);
}
return sprintf(self::MESSAGE, $this->toString(), $code, $error);
}
示例9: getStatus
/** Accessor for $_status.
*
* @param bool $asString
*
* @return int
*/
public function getStatus($asString = false)
{
return $asString ? Zend_Http_Response::responseCodeAsText($this->_status) : $this->_status;
}
示例10: parseRawResponse
/**
* Extract the API response data from the given HTTP response object.
*
* @param Zend_Http_Response $response
*
* @return $this
*/
protected function parseRawResponse(Zend_Http_Response $response)
{
if ($response->isSuccessful()) {
$content = $response->getBody();
if (strlen($content) > 0) {
try {
$xml = simplexml_load_string($response->getBody());
} catch (Exception $e) {
// Failed to parse XML
$this->successful = false;
$this->setMessage("Failed to parse a response from Klevu.");
Mage::helper('klevu_search')->log(Zend_Log::ERR, sprintf("Failed to parse XML response: %s", $e->getMessage()));
return $this;
}
$this->xml = $xml;
$this->successful = true;
} else {
// Response contains no content
$this->successful = false;
$this->setMessage('Failed to parse a response from Klevu.');
Mage::helper('klevu_search')->log(Zend_Log::ERR, "API response content is empty.");
}
} else {
// Unsuccessful HTTP response
$this->successful = false;
switch ($response->getStatus()) {
case 403:
$message = "Incorrect API keys.";
break;
case 500:
$message = "API server error.";
break;
case 503:
$message = "API server unavailable.";
break;
default:
$message = "Unexpected error.";
}
$this->setMessage(sprintf("Failed to connect to Klevu: %s", $message));
Mage::helper('klevu_search')->log(Zend_Log::ERR, sprintf("Unsuccessful HTTP response: %s %s", $response->getStatus(), $response->responseCodeAsText($response->getStatus())));
}
return $this;
}
示例11: __construct
public function __construct($responseCode, $message = null)
{
parent::__construct(null !== $message ? $message : Zend_Http_Response::responseCodeAsText($responseCode), self::ERROR_CODE_BASE + (int) $responseCode);
$this->_responseCode = $responseCode;
}
示例12: setHeaderStatus
/**
* Send the $exception's code or $code as the formal HTTP status of the response.
*
* @param integer $code suggested HTTP response code, if exception fails to provide one
* @param Exception $exception OPTIONAL HTTP status code
* @return string status code and description
*/
private static function setHeaderStatus($code, Exception $exception = null)
{
switch ($code) {
case 404:
$status = '404 Not Found';
break;
case 500:
$status = '500 Internal Server Error';
break;
default:
require_once 'Zend/Http/Response.php';
$status = $code . ' ' . Zend_Http_Response::responseCodeAsText($code);
}
if ('cgi' !== substr(php_sapi_name(), 0, 3) && !empty($_SERVER['SERVER_PROTOCOL'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status, true);
} else {
header('Status: ' . $status, true);
}
return $status;
}