本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface::getReasonPhrase方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getReasonPhrase方法的具体用法?PHP ResponseInterface::getReasonPhrase怎么用?PHP ResponseInterface::getReasonPhrase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::getReasonPhrase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(ResponseInterface $response)
{
try {
$this->details = $response->json();
$message = isset($this->details['error']['message']) ? $this->details['error']['message'] : $response->getReasonPhrase();
} catch (ParseException $e) {
$message = $response->getReasonPhrase();
}
parent::__construct(sprintf('The request failed and returned an invalid status code ("%d") : %s', $response->getStatusCode(), $message), $response->getStatusCode());
}
示例2: parseHeaders
private function parseHeaders(ResponseInterface $response, array &$data)
{
$data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
if ($requestId = $response->getHeader('x-amz-request-id')) {
$data['request_id'] = $requestId;
$data['message'] .= " (Request-ID: {$requestId})";
}
}
示例3: buildMessage
/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @return string
*/
protected function buildMessage($request, $response)
{
$resource = $this->getResponseBody();
if (is_null($resource)) {
$resource = '';
}
$message = sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s: %s', $request->getUrl(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase(), $resource);
return $message;
}
示例4: __construct
/**
* @param string $message
* @param RequestInterface $request
* @param ResponseInterface $response
*/
public function __construct($message = null, RequestInterface $request = null, ResponseInterface $response = null)
{
$message = $message ?: $this->message;
if ($request !== null && $response !== null) {
$details = "[url] " . $request->getUrl();
$details .= " [status code] " . $response->getStatusCode();
$details .= " [reason phrase] " . $response->getReasonPhrase();
$details .= ApiResponseException::getErrorDetails($response);
$message .= "\nDetails:\n " . wordwrap($details);
}
parent::__construct($message, $this->code);
}
示例5: create
/**
* Factory method to create a new exception with a normalized error message
*
* @param RequestInterface $request Request
* @param ResponseInterface $response Response received
* @param \Exception $previous Previous exception
*
* @return self
*/
public static function create(RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null)
{
if (!$response) {
return new self('Error completing request', $request, null, $previous);
}
$level = floor($response->getStatusCode() / 100);
if ($level == '4') {
$label = 'Client error response';
$className = __NAMESPACE__ . '\\ClientException';
} elseif ($level == '5') {
$label = 'Server error response';
$className = __NAMESPACE__ . '\\ServerException';
} else {
$label = 'Unsuccessful response';
$className = __CLASS__;
}
$message = $label . ' [url] ' . $request->getUrl() . ' [status code] ' . $response->getStatusCode() . ' [reason phrase] ' . $response->getReasonPhrase();
return new $className($message, $request, $response, $previous);
}
示例6: getErrorMessage
/**
* Extract more detailed error message.
*
* @param Response $response
* @return string
*/
protected function getErrorMessage(Response $response)
{
// This is the default:
$error = $response->getReasonPhrase();
// e.g. "Bad Request"
try {
// We might be able to fetch an error message from the response
$responseData = $response->json();
if (isset($responseData['title'])) {
$error = $responseData['title'];
}
if (isset($responseData['detail'])) {
$error .= ': ' . $responseData['detail'];
}
} catch (ParseException $e) {
// Do nothing
}
return (string) $error;
}
示例7: extractErrorMessage
/**
* Extract more detailed error message.
*
* @param Response $response
* @return string
*/
protected function extractErrorMessage(Response $response)
{
// This is the default
$error = $response->getReasonPhrase();
// e.g. "Bad Request"
try {
// We might be able to fetch an error message from the response
$responseData = $response->json();
if (isset($responseData['results'])) {
$result = $responseData['results'];
if (isset($result['errors']) && is_array($result['errors']) && count($result['errors']) > 0) {
$error = current($result['errors']);
} elseif (isset($result['error'])) {
$error = $result['error'];
}
}
} catch (ParseException $e) {
// Do nothing
}
return (string) $error;
}
示例8: validateResponse
/**
* Validate the response.
*
* @return $this
*/
protected function validateResponse()
{
$body = $this->request->getBody();
$this->response = $body->getContents();
// Send new request
if ($this->request == false || $this->request->getReasonPhrase() != 'OK') {
$this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
$this->objDebug->addDebug("Error Response", substr($this->response, 0, 4096));
throw new \RuntimeException("Error on transmission, with message: " . $this->request->getStatusCode());
}
$this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
// Build response Header information.
$strResponseHeader = "";
$arrHeaderKeys = array_keys($this->request->getHeaders());
foreach ($arrHeaderKeys as $keyHeader) {
$strResponseHeader .= $keyHeader . ": " . $this->request->getHeader($keyHeader) . "\n";
}
$this->objDebug->addDebug("Response", $strResponseHeader . "\n\n" . $this->request->getBody()->read(2048));
// Check if we have a response
if (strlen($this->response) == 0) {
throw new \RuntimeException("We got a blank response from server.");
}
// Check for "Fatal error" on client side
if (strpos($this->response, "Fatal error") !== false) {
throw new \RuntimeException("We got a Fatal error on client site. " . $this->response);
}
// Check for "Warning" on client side
if (strpos($this->response, "Warning") !== false) {
$intStart = stripos($this->response, "<strong>Warning</strong>:");
$intEnd = stripos($this->response, "on line");
if ($intEnd === false) {
$intLength = strlen($this->response) - $intStart;
} else {
$intLength = $intEnd - $intStart;
}
throw new \RuntimeException("We got a Warning on client site.<br /><br />" . substr($this->response, $intStart, $intLength));
}
return $this;
}
示例9: __construct
/**
*
* @param HttpResponse $response
* @param HttpRequest $request
*/
public function __construct(HttpResponse $response, HttpRequest $request = null)
{
$this->response = $response;
$this->request = $request;
parent::__construct($response->getReasonPhrase(), $response->getStatusCode());
}
示例10: reasonPhrase
/**
* @return string|null
*/
public function reasonPhrase()
{
return $this->response->getReasonPhrase();
}
示例11: format
/**
* Returns a formatted message
*
* @param RequestInterface $request Request that was sent
* @param ResponseInterface $response Response that was received
* @param \Exception $error Exception that was received
* @param array $customData Associative array of custom template data
*
* @return string
*/
public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = array())
{
$cache = $customData;
$that = $this;
return preg_replace_callback('/{\\s*([A-Za-z_\\-\\.0-9]+)\\s*}/', function (array $matches) use($request, $response, $error, &$cache, $that) {
if (isset($cache[$matches[1]])) {
return $cache[$matches[1]];
}
$result = '';
switch ($matches[1]) {
case 'request':
$result = $request;
break;
case 'response':
$result = $response;
break;
case 'req_headers':
$result = trim($request->getMethod() . ' ' . $request->getResource()) . ' HTTP/' . $request->getProtocolVersion() . "\r\n" . $that->headers($request);
break;
case 'res_headers':
$result = $response ? sprintf('HTTP/%s %d %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()) . "\r\n" . $that->headers($response) : 'NULL';
break;
case 'req_body':
$result = $request->getBody();
break;
case 'res_body':
$result = $response ? $response->getBody() : 'NULL';
break;
case 'ts':
$result = gmdate('c');
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'req_version':
$result = $request->getProtocolVersion();
break;
case 'res_version':
$result = $response ? $response->getProtocolVersion() : 'NULL';
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'code':
$result = $response ? $response->getStatusCode() : 'NULL';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : 'NULL';
break;
case 'error':
$result = $error ? $error->getMessage() : 'NULL';
break;
default:
// handle prefixed dynamic headers
if (strpos($matches[1], 'req_header_') === 0) {
$result = $request->getHeader(substr($matches[1], 11));
} elseif (strpos($matches[1], 'res_header_') === 0) {
$result = $response ? $response->getHeader(substr($matches[1], 11)) : 'NULL';
}
}
$cache[$matches[1]] = $result;
return $result;
}, $this->template);
}
示例12: _parseResponse
/**
* @param ResponseInterface $response
* @return mixed
* @throws \Exception
*/
protected function _parseResponse(ResponseInterface $response)
{
$statusCode = $response->getStatusCode();
if ($statusCode >= 400 && $statusCode < 500) {
$message = (string) $response->getBody();
if (!$message) {
$message = $response->getReasonPhrase();
}
switch ($statusCode) {
case self::STATUS_CODE_UNAUTHORIZED:
case self::STATUS_CODE_FORBIDDEN:
throw new \Exception($message, $statusCode);
case self::STATUS_CODE_BAD_REQUEST:
if (strpos($message, "Couldn't find series:") !== false) {
throw new \Exception($message, $statusCode);
}
}
throw new \Exception($message, $statusCode);
} else {
if ($statusCode == self::STATUS_CODE_OK) {
try {
return $response->json();
} catch (ParseException $ex) {
throw new \Exception(sprintf("%s; Response is '%s'", $ex->getMessage(), (string) $response->getBody()), $ex->getCode(), $ex);
}
} else {
if ($statusCode > 200 && $statusCode < 300) {
return true;
}
}
}
throw new \Exception((string) $response->getBody(), $statusCode);
}
示例13: __construct
public function __construct(ResponseInterface $response)
{
parent::__construct($response->getReasonPhrase(), $response->getStatusCode());
$this->response = $response;
}
示例14: getParameters
/**
* Get context fields to add to the time-line entry.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param Exception $error
*
* @return array
*/
protected function getParameters(RequestInterface $request, ResponseInterface $response = null, Exception $error = null)
{
$params = [];
$keys = array_intersect($this->context, $this->availableParameters);
foreach ($keys as $key) {
switch ($key) {
case 'request':
$result = $request;
break;
case 'response':
$result = $response;
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'request_version':
$result = $request->getProtocolVersion();
break;
case 'response_version':
$result = $response ? $response->getProtocolVersion() : 'NULL';
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'status_code':
$result = $response ? $response->getStatusCode() : 'NULL';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : 'NULL';
break;
case 'error':
$result = $error ? $error->getMessage() : 'NULL';
break;
}
$params[$key] = (string) $result ?: '';
}
return $params;
}
示例15: createResponse
private function createResponse(GuzzleResponse $response)
{
$body = $response->getBody();
return new Response($response->getStatusCode(), $response->getHeaders(), isset($body) ? $body->detach() : null, $response->getProtocolVersion(), $response->getReasonPhrase());
}