当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::getStatusCode方法代码示例

本文整理汇总了PHP中Zend\Http\Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Response的用法示例。


在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testResponseCanSetCustomStatusCode

 public function testResponseCanSetCustomStatusCode()
 {
     $response = new Response();
     $this->assertEquals(200, $response->getStatusCode());
     $response->setCustomStatusCode('999');
     $this->assertEquals(999, $response->getStatusCode());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:7,代码来源:ResponseTest.php

示例2: testResponseCanSetStatusCode

 public function testResponseCanSetStatusCode()
 {
     $response = new Response();
     $this->assertEquals(200, $response->getStatusCode());
     $response->setStatusCode('303');
     $this->assertEquals(303, $response->getStatusCode());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:7,代码来源:ResponseTest.php

示例3: setDefaultResponseValues

 /**
  * Sets the default response values (server raw response, return code, return message and request name)
  *
  * @param ActionResponseInterface $actionResponse
  */
 protected function setDefaultResponseValues(ActionResponseInterface $actionResponse)
 {
     $this->serverRawResponse = $actionResponse->getResponse();
     $this->returnCode = $this->serverRawResponse->getStatusCode();
     $this->returnMessage = $this->serverRawResponse->getReasonPhrase();
     $this->requestName = $actionResponse->getRequestName();
 }
开发者ID:mslib,项目名称:remote-host,代码行数:12,代码来源:AbstractResponseWrapper.php

示例4: __construct

 /**
  * Build the API response from the given HTTP response
  *
  * @param Response $httpResponse
  */
 public function __construct(Response $httpResponse)
 {
     $this->setHttpResponse($httpResponse);
     // Looking for HTTP error
     $statusCode = $this->httpResponse->getStatusCode();
     if (!($statusCode > 199 && $statusCode < 300)) {
         $this->isError = true;
         $this->setErrorMessage($this->httpResponse->getReasonPhrase());
     }
     $contentType = $httpResponse->getHeaders()->get('content-type')->getFieldValue();
     if (strpos($contentType, 'application/vnd.zend.serverapi+xml') === 0) {
         // Looking for XML error
         libxml_use_internal_errors(true);
         $xml = simplexml_load_string($httpResponse->getBody());
         if (!$xml) {
             $errorMessage = '';
             foreach (libxml_get_errors() as $error) {
                 $errorMessage .= $error->message . "\n";
             }
             $this->isError = true;
             $this->setErrorMessage($errorMessage);
             return;
         }
         // Lookign for API error
         if ($xml->errorData) {
             $this->isError = true;
             $this->setErrorMessage((string) $xml->errorData->errorMessage);
             $this->setApiErrorCode((string) $xml->errorData->errorCode);
             return;
         }
         $this->setXml($xml);
     }
 }
开发者ID:Karl-Dawson,项目名称:ZendServerWebApiModule,代码行数:38,代码来源:ApiResponse.php

示例5: handleResponse

 /**
  * {@inheritdoc}
  * @see \InoOicClient\Oic\AbstractResponseHandler::handleResponse()
  */
 public function handleResponse(\Zend\Http\Response $httpResponse)
 {
     $responseData = null;
     $decodeException = null;
     try {
         $responseData = $this->getJsonCoder()->decode($httpResponse->getBody());
     } catch (\Exception $e) {
         $decodeException = $e;
     }
     if (!$httpResponse->isSuccess()) {
         if (isset($responseData[Param::ERROR])) {
             $error = $this->getErrorFactory()->createErrorFromArray($responseData);
             $this->setError($error);
             return;
         } else {
             throw new HttpErrorStatusException(sprintf("Error code '%d' from server", $httpResponse->getStatusCode()));
         }
     }
     if (null !== $decodeException) {
         throw new InvalidResponseFormatException('The HTTP response does not contain valid JSON', null, $decodeException);
     }
     try {
         $this->response = $this->getResponseFactory()->createResponse($responseData);
     } catch (\Exception $e) {
         throw new Exception\InvalidResponseException(sprintf("Invalid response: [%s] %s", get_class($e), $e->getMessage()), null, $e);
     }
 }
开发者ID:publicitas-deployment,项目名称:php-openid-connect-client,代码行数:31,代码来源:ResponseHandler.php

示例6: theStatusCodeShouldBe

 /**
  * @Then the status code should be :code
  */
 public function theStatusCodeShouldBe($code)
 {
     if ($this->response->getStatusCode() != $code) {
         echo $this->response->getBody();
     }
     \PHPUnit_Framework_Assert::assertEquals($code, $this->response->getStatusCode());
 }
开发者ID:continuousphp,项目名称:deploy-agent,代码行数:10,代码来源:DeployAgentContext.php

示例7: dispatchRequestAndDecodeResponse

 protected function dispatchRequestAndDecodeResponse($url, $method, $data = null)
 {
     $request = new Request();
     $this->lastResponse = null;
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Accept' => 'application/json', 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0'));
     if (!empty($this->host)) {
         $request->getHeaders()->addHeaders(array('Host' => $this->host));
     }
     if (!empty($this->key)) {
         $request->getHeaders()->addHeaders(array('Authorization' => 'Bearer ' . $this->key));
     }
     $request->setUri($url);
     $request->setMethod($method);
     if (is_null($data)) {
         $data = array();
     }
     if (isset($this->key)) {
         $data["auth"] = $this->key;
     }
     if ($method == "POST" || $method == "PUT") {
         $request->setPost(new Parameters($data));
         if (isset($this->key)) {
             $request->setQuery(new Parameters(array('auth' => $this->key)));
         }
     } else {
         $request->setQuery(new Parameters($data));
     }
     $this->lastResponse = $this->httpClient->send($request);
     if ($this->lastResponse->isSuccess()) {
         return json_decode($this->lastResponse->getBody(), true);
     } else {
         return array('error' => true, 'headers' => array("code" => $this->lastResponse->getStatusCode(), "reasons" => $this->lastResponse->getReasonPhrase()), 'body' => json_decode($this->lastResponse->getBody(), true));
     }
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:34,代码来源:Client.php

示例8: setResponseContent

 protected function setResponseContent(Response $response, array $data)
 {
     if ($response instanceof \Zend\Http\PhpEnvironment\Response) {
         $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
         $response->setContent(json_encode(array_merge(array('status' => $response->getStatusCode()), $data)));
     }
     return $response;
 }
开发者ID:fousheezy,项目名称:auth,代码行数:8,代码来源:Api.php

示例9: testSet201StatusCodeIfPost

 public function testSet201StatusCodeIfPost()
 {
     $request = new HttpRequest();
     $request->setMethod(HttpRequest::METHOD_POST);
     $this->event->setRequest($request);
     $this->response->setContent('foo');
     $this->resourceResponseListener->finishResponse($this->event);
     $this->assertEquals(201, $this->response->getStatusCode());
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:9,代码来源:ResourceResponseListenerTest.php

示例10: checkStatusCode

 /**
  * Checks whether to handle this status code.
  *
  * @param  HttpResponse $response
  * @return boolean
  */
 public function checkStatusCode(HttpResponse $response)
 {
     // Only 200 responses are cached by default
     if (empty($this->config['http_codes_black_list'])) {
         return $response->isOk();
     }
     $statusCode = $response->getStatusCode();
     return !in_array($statusCode, (array) $this->config['http_codes_black_list']);
 }
开发者ID:zfcampus,项目名称:zf-http-cache,代码行数:15,代码来源:HttpCacheListener.php

示例11: createFromResponse

 /**
  * Exception factory.
  *
  * Returns a RequestErrorException or RemoteErrorException depending on
  * the response's status code.
  *
  * @param Response $response Server response
  *
  * @return RequestErrorException|RemoteErrorException
  */
 public static function createFromResponse(Response $response)
 {
     $status = $response->getStatusCode();
     $phrase = $response->getReasonPhrase();
     if ($status >= 500) {
         return new RemoteErrorException($status . ' ' . $phrase, $status, $response);
     } else {
         return new RequestErrorException($status . ' ' . $phrase, $status, $response);
     }
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:20,代码来源:HttpErrorException.php

示例12: __construct

 /**
  * Construtor.
  *
  * @param Zend\Http\Client   $client
  * @param Zend\Http\Response $response
  */
 public function __construct(ZendHttpClient $client, ZendHttpResponse $response, $depth = 0)
 {
     $this->httpClient = $client;
     $this->httpResponse = $response;
     if (!$this->httpResponse->isSuccess()) {
         $error = json_decode($this->httpResponse->getBody());
         if (empty($error)) {
             $error = new \stdClass();
             $error->status = $this->httpResponse->getStatusCode();
             $error->title = $this->httpResponse->getReasonPhrase();
             $error->detail = '';
         }
         if (!isset($error->status)) {
             $error->status = 500;
         }
         if (!isset($error->detail)) {
             $error->detail = 'An error occurred.';
         }
         throw new RuntimeException(json_encode($error, null, 100), $error->status);
     }
     if (!$this->httpResponse->getHeaders()->has('Content-Type')) {
         throw new RuntimeException("Missing 'Content-Type' header.", 500);
     }
     $contentType = $this->httpResponse->getHeaders()->get('Content-Type')->getFieldValue();
     $pos = strpos($contentType, ';');
     if ($pos !== false) {
         $contentType = substr($contentType, 0, $pos);
     }
     if (empty($this->httpResponse->getBody())) {
         $this->content = null;
     } elseif ($contentType == 'application/hal+json' || $contentType == 'application/json') {
         $this->content = new Resource(Hal::fromJson($this->httpResponse->getBody(), $depth));
     } elseif ($contentType == 'application/hal+xml' || $contentType == 'application/xml') {
         $this->content = new Resource(Hal::fromXml($this->httpResponse->getBody(), $depth));
     } else {
         throw new RuntimeException("Unable to handle content type '{$contentType}' for response: '{$this->httpResponse->getBody()}'.", 500);
     }
 }
开发者ID:mt-olympus,项目名称:hermes,代码行数:44,代码来源:Response.php

示例13: __construct

 /**
  * Construtor
  *
  * @param Zend\Http\Client   $client
  * @param Zend\Http\Response $response
  */
 public function __construct(ZendHttpClient $client, ZendHttpResponse $response)
 {
     $this->httpClient = $client;
     $this->httpResponse = $response;
     try {
         $this->checkResponseStatus();
         if (204 == $this->httpResponse->getStatusCode()) {
             $this->strategyContent = new EmptyContent($this->httpClient, $this->httpResponse);
         } else {
             $contentType = $this->httpResponse->getHeaders()->get('Content-Type')->getFieldValue();
             switch (trim($contentType)) {
                 case HalJson::CONTENT_TYPE:
                     $this->strategyContent = new HalJson($this->httpClient, $this->httpResponse);
                     break;
                 default:
                     $errorMessage = sprintf('The apigility server returned a mime type ("%s") that cannot be parsed by apigility client', $mimeType);
                     return new TriggerException($this->httpClient, $this->httpResponse, $errorMessage);
             }
         }
     } catch (RuntimeException $e) {
         throw $e;
     }
 }
开发者ID:ma-si,项目名称:apigility-client,代码行数:29,代码来源:Response.php

示例14: send

 /**
  * Send Http request to retrieve datas
  * @access protected
  * @param  string                                $service    Service to call
  * @param  string                                $type       Resource type to retrieve (for search service)
  * @param  array                                 $parameters Parameters used for request
  * @throws \Zend\Http\Exception\RuntimeException
  * @return \stdClass
  */
 protected function send($service, $type, $parameters)
 {
     // reset old parameters
     $this->getHttpClient()->resetParameters();
     // setup Http headers
     $headers = array(ContentTypeHeader::fromString('Content-Type: ' . HttpClient::ENC_URLENCODED));
     // setup HttpClient
     $this->getHttpClient()->setMethod(HttpRequest::METHOD_GET);
     $this->getHttpClient()->setParameterGet($parameters);
     $this->getHttpClient()->setHeaders($headers);
     // generate URI and set to HttpClient
     $this->getHttpClient()->setUri($this->generateURI($service, $type));
     // get HttpResponse
     $this->response = $this->getHttpClient()->send();
     // is HttpRequest ok ?
     if (!$this->response->isOk()) {
         // throw RuntimeException
         throw new ZendRuntimeException(sprintf('Invalid status code: %d', $this->response->getStatusCode()));
     }
     // return decode object
     return \Zend\Json\Decoder::decode($this->response->getBody());
 }
开发者ID:ze-pequeno,项目名称:pequeno-spotify-module,代码行数:31,代码来源:SpotifyService.php

示例15: toHttpFoundationResponse

 /**
  * Transforms a Zend\Http\Response into an HttpFoundation one.
  * 
  * @param ZendResponse $zresponse The Zend\Http\Response
  * 
  * @return HttpFoundationResponse
  */
 public static function toHttpFoundationResponse(ZendResponse $zresponse)
 {
     return HttpFoundationResponse::create($zresponse->getContent(), $zresponse->getStatusCode(), $zresponse->getHeaders()->toArray());
 }
开发者ID:fwk,项目名称:security,代码行数:11,代码来源:RequestBridge.php


注:本文中的Zend\Http\Response::getStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。