本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getStatusCode方法的具体用法?PHP ResponseInterface::getStatusCode怎么用?PHP ResponseInterface::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: userMovedFile
/**
* @Given /^User "([^"]*)" moved file "([^"]*)" to "([^"]*)"$/
* @param string $user
* @param string $fileSource
* @param string $fileDestination
*/
public function userMovedFile($user, $fileSource, $fileDestination)
{
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$headers['Destination'] = $fullUrl . $fileDestination;
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
PHPUnit_Framework_Assert::assertEquals(201, $this->response->getStatusCode());
}
示例2: isNotJsonError
private function isNotJsonError(HttpResponseInterface $httpResponse)
{
if ($httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_NOT_FOUND || $httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_INTERNAL_SERVER_ERROR || $httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_METHOD_NOT_ALLOWED) {
return true;
}
return false;
}
示例3: _getResult
/**
* @param ResponseInterface $response
*
* @return ApiResult
*/
protected function _getResult($response)
{
if (!$response instanceof ResponseInterface) {
throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
}
$result = new ApiResult();
$result->setStatusCode($response->getStatusCode());
$callId = $response->getHeader('X-Call-Id');
if (!empty($callId)) {
$result->setCallId($callId);
}
$decoded = json_decode((string) $response->getBody());
if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
$meta = $decoded->meta;
$data = $decoded->data;
if (isset($meta->message)) {
$result->setStatusMessage($meta->message);
}
$result->setContent(json_encode($data));
} else {
$result->setContent((string) $response->getBody());
}
$result->setHeaders($response->getHeaders());
return $result;
}
示例4: status
/**
* Asserts the HTTP response status code.
*
* @param string $status Expected status code
*
* @throws \RuntimeException If status code does not match
*
* @return self
*/
public function status($status)
{
$httpStatus = (string) $this->response->getStatusCode();
if ($httpStatus !== $status) {
throw new \RuntimeException("Unexpected response status code: {$httpStatus}");
}
return $this;
}
示例5: setResponse
/**
* Set Http response in case of successful request
*
* @param GuzzleHttp\Message\ResponseInterface $response
* @return CurrencyExchange\HttpClient
* @throws CurrencyExchange\Exception\ResponseException
*/
public function setResponse(ResponseInterface $response)
{
if ($response->getStatusCode() != 200) {
throw new ResponseException('Unsuccessful HTTP request: ' . $response->getStatusCode() . ' on ' . $this->getUri());
}
$this->_response = $response;
return $this;
}
示例6: __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());
}
示例7: theCaldavHttpStatusCodeShouldBe
/**
* @Then The CalDAV HTTP status code should be :code
*/
public function theCaldavHttpStatusCodeShouldBe($code)
{
if ((int) $code !== $this->response->getStatusCode()) {
throw new \Exception(sprintf('Expected %s got %s', (int) $code, $this->response->getStatusCode()));
}
$body = $this->response->getBody()->getContents();
if ($body && substr($body, 0, 1) === '<') {
$reader = new Sabre\Xml\Reader();
$reader->xml($body);
$this->responseXml = $reader->parse();
}
}
示例8: readNext
/**
* {@inheritdoc}
*/
protected function readNext()
{
if (!$this->iterator->valid()) {
return;
}
$message = $this->iterator->current();
$code = $this->response->getStatusCode();
$content = sprintf("HTTP/1.1 300\r\n %s", $message);
$element = $this->parser->parseResponse($content);
$current = $this->factory->createResponse($code, $element['headers'], $element['body']);
return $current;
}
示例9: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
}
示例10: decodeHttpResponse
/**
* Decode an HTTP Response.
* @static
* @throws Google_Service_Exception
* @param GuzzleHttp\Message\RequestInterface $response The http response to be decoded.
* @param GuzzleHttp\Message\ResponseInterface $response
* @return mixed|null
*/
public static function decodeHttpResponse(ResponseInterface $response, RequestInterface $request = null)
{
$body = (string) $response->getBody();
$code = $response->getStatusCode();
$result = null;
// return raw response when "alt" is "media"
$isJson = !($request && 'media' == $request->getQuery()->get('alt'));
// set the result to the body if it's not set to anything else
if ($isJson) {
try {
$result = $response->json();
} catch (ParseException $e) {
$result = $body;
}
} else {
$result = $body;
}
// retry strategy
if (intVal($code) >= 300) {
$errors = null;
// Specific check for APIs which don't return error details, such as Blogger.
if (isset($result['error']) && isset($result['error']['errors'])) {
$errors = $result['error']['errors'];
}
throw new Google_Service_Exception($body, $code, null, $errors);
}
return $result;
}
示例11: updatingLastShare
/**
* @When /^Updating last share with$/
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function updatingLastShare($body)
{
$share_id = $this->lastShareData->data[0]->id;
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$share_id}";
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$this->currentUser, $this->regularUser];
}
if ($body instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $body->getRowsHash();
if (array_key_exists('expireDate', $fd)) {
$dateModification = $fd['expireDate'];
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
}
$options['body'] = $fd;
}
try {
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
}
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
}
示例12: modifyRedirectRequest
private function modifyRedirectRequest(RequestInterface $request, ResponseInterface $response)
{
$config = $request->getConfig();
// Use a GET request if this is an entity enclosing request and we are
// not forcing RFC compliance, but rather emulating what all browsers
// would do.
$statusCode = $response->getStatusCode();
if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
$request->setMethod('GET');
$request->setBody(null);
}
$previousUrl = $request->getUrl();
$this->setRedirectUrl($request, $response);
$this->rewindEntityBody($request);
// Add the Referer header if it is told to do so and only
// add the header if we are not redirecting from https to http.
if ($config->getPath('redirect/referer') && ($request->getScheme() == 'https' || $request->getScheme() == $config['redirect_scheme'])) {
$url = Url::fromString($previousUrl);
$url->setUsername(null);
$url->setPassword(null);
$request->setHeader('Referer', (string) $url);
} else {
$request->removeHeader('Referer');
}
}
示例13: theResponseCodeShouldBe
/**
* Checks that response has specific status code.
*
* @param string $code status code
*
* @Then /^(?:the )?response code should be (\d+)$/
*/
public function theResponseCodeShouldBe($code)
{
$expected = intval($code);
var_dump($this->response->getStatusCode());
$actual = intval($this->response->getStatusCode());
Assertions::assertSame($expected, $actual);
}
示例14: 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})";
}
}
示例15: __construct
/**
* Gets the relevant data from the Guzzle clients.
*
* @param RequestInterface $request
* @param ResponseInterface $response
*/
public function __construct(RequestInterface $request, ResponseInterface $response)
{
if ($response instanceof FutureResponse) {
$this->httpStatusCode = null;
} else {
$this->httpStatusCode = $response->getStatusCode();
}
$this->requestUrl = $request->getUrl();
}