本文整理汇总了PHP中Guzzle\Http\Message\Response::getReasonPhrase方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getReasonPhrase方法的具体用法?PHP Response::getReasonPhrase怎么用?PHP Response::getReasonPhrase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::getReasonPhrase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: debug
public function debug()
{
$r = new Response();
var_dump($r->getReasonPhrase());
$req = new Request();
$req->getPath();
}
示例2: factory
/**
* Simple exception factory for creating Intercom standardised exceptions
*
* @param RequestInterface $request The Request
* @param Response $response The response
* @return BadResponseException
*/
public static function factory(RequestInterface $request, Response $response)
{
if (!static::isValidIntercomError($response->json())) {
$label = 'Unsuccessful response';
$class = __CLASS__;
} elseif ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
// Sets the errors if the error response is the standard Intercom error type
if (static::isValidIntercomError($response->json())) {
$e->setErrors($response->json()['errors']);
}
return $e;
}
示例3: factory
/**
* Simple exception factory for creating Intercom standardised exceptions
*
* @param RequestInterface $request The Request
* @param Response $response The response
* @return BadResponseException
*/
public static function factory(RequestInterface $request, Response $response)
{
$response_json = $response->json();
$intercom_unavailable_error = NULL;
if (!static::isValidIntercomError($response_json)) {
if ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
$intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
} elseif ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
// Sets the errors if the error response is the standard Intercom error type
if (static::isValidIntercomError($response_json)) {
$e->setErrors($response_json['errors']);
} elseif ($intercom_unavailable_error != NULL) {
$e->setErrors(array('code' => 'service_unavailable', "message" => $intercom_unavailable_error));
}
return $e;
}
示例4: factory
/**
* Factory method to create a new Oauth exception.
*
* @param RequestInterface $request
* @param Response $response
*
* @return OauthException
*/
public static function factory(RequestInterface $request, Response $response)
{
$message = 'Client error response' . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new static($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
}
示例5: parseHeaders
/**
* Parses additional exception information from the response headers
*
* @param RequestInterface $request Request that was issued
* @param Response $response The response from the request
* @param array $data The current set of exception data
*/
protected function parseHeaders(RequestInterface $request, Response $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})";
}
}
示例6: prepareResponse
protected function prepareResponse(Response $data)
{
if ($data->getStatusCode() != 200) {
throw new \InvalidArgumentException($data->getReasonPhrase());
}
$response = json_decode($data->getBody(), true);
$this->validateResponse($response);
return $response;
}
示例7: createResponse
/**
* Prepares an EmbeddedResponse from the original response and data
*
* @param Guzzle\Http\Message\Response $originalResponse
* @param array $data
*
* @return Desk\Relationship\Resource\EmbeddedResponse
*/
public function createResponse(Response $originalResponse, array $data)
{
$statusCode = $originalResponse->getStatusCode();
$reasonPhrase = $originalResponse->getReasonPhrase();
$headers = $originalResponse->getHeaders();
$body = json_encode($data);
// set reason phrase -- needs to be done vie
$response = $this->newResponse($statusCode, $headers, $body);
$response->setReasonPhrase($reasonPhrase);
return $response;
}
示例8: factory
public static function factory(RequestInterface $request, Response $response)
{
$label = 'Bearer error response';
$bearerReason = self::headerToReason($response->getHeader("WWW-Authenticate"));
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[bearer reason] ' . $bearerReason, '[url] ' . $request->getUrl()));
$e = new static($message);
$e->setResponse($response);
$e->setRequest($request);
$e->setBearerReason($bearerReason);
return $e;
}
示例9: factory
/**
* Factory method to create a new response exception based on the response code.
*
* @param RequestInterface $request Request
* @param Response $response Response received
* @param string $label
*
* @return BadResponseException
*/
public static function factory(RequestInterface $request, Response $response, $label = null)
{
if (!$label) {
if ($response->isClientError()) {
$label = 'Client error response';
} elseif ($response->isServerError()) {
$label = 'Server error response';
} else {
$label = 'Unsuccessful response';
}
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl(), '[content type] ' . $response->getContentType(), '[response body] ' . $response->getBody(true)));
$result = new static($message);
$result->setResponse($response);
$result->setRequest($request);
return $result;
}
示例10: factory
public static function factory(RequestInterface $request, Response $response)
{
if ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new self($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
}
示例11: format
/**
* Returns a formatted message
*
* @param RequestInterface $request Request that was sent
* @param Response $response Response that was received
* @param CurlHandle $handle Curl handle associated with the message
* @param array $customData Associative array of custom template data
*
* @return string
*/
public function format(RequestInterface $request, Response $response = null, CurlHandle $handle = null, array $customData = array())
{
$cache = $customData;
return preg_replace_callback('/{\\s*([A-Za-z_\\-\\.0-9]+)\\s*}/', function (array $matches) use($request, $response, $handle, &$cache) {
if (array_key_exists($matches[1], $cache)) {
return $cache[$matches[1]];
}
$result = '';
switch ($matches[1]) {
case 'request':
$result = (string) $request;
break;
case 'response':
$result = (string) $response;
break;
case 'req_body':
$result = $request instanceof EntityEnclosingRequestInterface ? (string) $request->getBody() : '';
break;
case 'res_body':
$result = $response ? $response->getBody(true) : '';
break;
case 'ts':
$result = gmdate('c');
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = (string) $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'protocol':
$result = 'HTTP';
break;
case 'version':
$result = $request->getProtocolVersion();
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'port':
$result = $request->getPort();
break;
case 'code':
$result = $response ? $response->getStatusCode() : '';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : '';
break;
case 'connect_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_CONNECT_TIME);
} elseif ($response) {
$result = $response->getInfo('connect_time');
}
break;
case 'total_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_TOTAL_TIME);
} elseif ($response) {
$result = $response->getInfo('total_time');
}
break;
case 'curl_error':
$result = $handle ? $handle->getError() : '';
break;
case 'curl_code':
$result = $handle ? $handle->getErrorNo() : '';
break;
case 'curl_stderr':
$result = $handle ? $handle->getStderr() : '';
break;
default:
if (strpos($matches[1], 'req_header_') === 0) {
$result = $request->getHeader(substr($matches[1], 11));
} elseif (strpos($matches[1], 'res_header_') === 0) {
$result = $response->getHeader(substr($matches[1], 11));
}
}
$cache[$matches[1]] = $result;
return $result;
}, $this->template);
}
示例12: testHandlesStatusAndStatusCodes
/**
* @covers Guzzle\Http\Message\Response::getReasonPhrase
* @covers Guzzle\Http\Message\Response::setStatus
*/
public function testHandlesStatusAndStatusCodes()
{
$response = new Response(200, new Collection(), 'body');
$this->assertEquals('OK', $response->getReasonPhrase());
$this->assertSame($response, $response->setStatus(204));
$this->assertEquals('No Content', $response->getReasonPhrase());
$this->assertEquals(204, $response->getStatusCode());
$this->assertSame($response, $response->setStatus(204, 'Testing!'));
$this->assertEquals('Testing!', $response->getReasonPhrase());
$this->assertEquals(204, $response->getStatusCode());
try {
$response->setStatus(2000);
$this->fail('Did not throw expected exception when setting an invalid status');
} catch (BadResponseException $e) {
}
}
示例13: visit
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
{
$value[$param->getName()] = $response->getReasonPhrase();
}
示例14: testHandlesStatusAndStatusCodes
/**
* @covers Guzzle\Http\Message\Response::getReasonPhrase
* @covers Guzzle\Http\Message\Response::setStatus
*/
public function testHandlesStatusAndStatusCodes()
{
$response = new Response(200, new Collection(), 'body');
$this->assertEquals('OK', $response->getReasonPhrase());
$this->assertSame($response, $response->setStatus(204));
$this->assertEquals('No Content', $response->getReasonPhrase());
$this->assertEquals(204, $response->getStatusCode());
$this->assertSame($response, $response->setStatus(204, 'Testing!'));
$this->assertEquals('Testing!', $response->getReasonPhrase());
$this->assertEquals(204, $response->getStatusCode());
$response->setStatus(2000);
$this->assertEquals(2000, $response->getStatusCode());
$this->assertEquals('', $response->getReasonPhrase());
$response->setStatus(200, 'Foo');
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Foo', $response->getReasonPhrase());
}
示例15: getDelay
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($response) {
return isset($this->errorCodes[$response->getReasonPhrase()]) ? true : null;
}
}