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


PHP Response::getStatusCode方法代码示例

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


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

示例1: testGetStatusCodeReturnsTheStatusCode

 public function testGetStatusCodeReturnsTheStatusCode()
 {
     $response = new Response();
     $this->assertEquals($response->getStatusCode(), null);
     $response->addHeader('1.0 200 OK');
     $this->assertEquals($response->getStatusCode(), 200);
 }
开发者ID:philip,项目名称:Buzz,代码行数:7,代码来源:ResponseTest.php

示例2: 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);
 }
开发者ID:softr,项目名称:asaas-php-sdk,代码行数:10,代码来源:GuzzleHttpAdapter.php

示例3: testSetError

 /** @dataProvider provideSetError */
 public function testSetError($expected, $statusCode, $error, $error_description = null, $error_uri = null)
 {
     $response = new Response();
     $response->setError($statusCode, $error, $error_description, $error_uri);
     $this->assertEquals($expected, $response->getContent());
     $this->assertEquals($statusCode, $response->getStatusCode());
 }
开发者ID:Insantani,项目名称:SourceTree-diovi,代码行数:8,代码来源:ResponseTest.php

示例4: testIfRedirectReturnsCorrectHttpCodeAndLocationHeader

 /**
  * @test
  * @param $url
  * @param $statusCode
  * @dataProvider redirectDataProvider
  */
 public function testIfRedirectReturnsCorrectHttpCodeAndLocationHeader($url, $statusCode)
 {
     $response = new Response();
     $response->redirect($url, $statusCode);
     $this->assertEquals($url, $response->headers->get('Location'));
     $this->assertEquals($statusCode, $response->getStatusCode());
 }
开发者ID:lcobucci,项目名称:action-mapper,代码行数:13,代码来源:ResponseTest.php

示例5: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody();
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     $error = $content->errors[0];
     throw new HttpException(isset($error) ? $error->description : 'Request not processed.', $code);
 }
开发者ID:skaisser,项目名称:organizze,代码行数:11,代码来源:GuzzleHttpAdapter.php

示例6: testResponseValues

 public function testResponseValues()
 {
     $resource = $this->prophesize(Resource::CLASS);
     $resource->asJson()->willReturn('foobar');
     $response = new Response($resource->reveal());
     $this->assertSame(200, $response->getStatusCode());
     $this->assertSame('application/hal+json', $response->getHeaderLine('Content-Type'));
     $this->assertSame('foobar', (string) $response->getBody());
 }
开发者ID:asylgrp,项目名称:workbench,代码行数:9,代码来源:ResponseTest.php

示例7: render

 /**
  * {@inheritdoc}
  */
 public function render(Request $request, Response $response)
 {
     if (!$this->environment->isSilent()) {
         header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage());
         foreach ($response->getHeaders() as $name => $value) {
             header($name . ': ' . $value);
         }
     }
     echo $this->createTemplate($response);
 }
开发者ID:itephp,项目名称:framework,代码行数:13,代码来源:HTTPErrorPresenter.php

示例8: terminate

 /**
  * Terminates application.
  *
  * Renders content or excute redirecting
  *
  * @param Response $response
  */
 public function terminate(Response $response)
 {
     if ($response->getRedirectUrl() === null) {
         header("Content-Type: {$response->getContentType()}; charset=utf-8");
         http_response_code($response->getStatusCode());
         $response->display();
     } else {
         header("Location: {$response->getRedirectUrl()}");
     }
     exit;
 }
开发者ID:serkin,项目名称:blog,代码行数:18,代码来源:Application.php

示例9: validateResponse

 /**
  * {@inheritdoc}
  */
 public function validateResponse(Request $request, Response $response) : bool
 {
     if (Response::SWITCHING_PROTOCOLS !== $response->getStatusCode()) {
         return false;
     }
     if ('upgrade' !== strtolower($response->getHeader('Connection'))) {
         return false;
     }
     if ('websocket' !== strtolower($response->getHeader('Upgrade'))) {
         return false;
     }
     $key = $request->getHeader('Sec-WebSocket-Key');
     if (!$response->hasHeader('Sec-WebSocket-Accept')) {
         return false;
     }
     return $this->responseKey($key) === $response->getHeader('Sec-WebSocket-Accept');
 }
开发者ID:icicleio,项目名称:websocket,代码行数:20,代码来源:Rfc6455Protocol.php

示例10: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     if ($response->data !== null) {
         $dom = new DOMDocument($this->version, $charset);
         $root = new DOMElement($this->rootTag);
         $result = new DOMElement($this->itemTag);
         $code = new DOMElement($this->itemTag);
         $status = new DOMElement($this->itemTag);
         $dom->appendChild($root);
         $code->appendChild($response->getStatusCode());
         $status->appendChild($response->getIsSuccessful() ? 'success' : 'error');
         $messageText = '';
         if (!$response->getIsOk()) {
             $messageText = $response->statusText;
         }
         if (is_string($response->data)) {
             //For string result we send it like 'message'
             $messageText = $response->data;
         } elseif ($response->getIsClientError() && isset($response->data['message'])) {
             //For HttpExceptions we save message field only to 'message'
             $messageText = $response->data['message'];
             unset($response->data['message']);
             $result->appendChild($response->data);
         } else {
             //Otherwise send all as result
             $result->appendChild($response->data);
         }
         if ($messageText !== '') {
             $message = new DOMElement($this->itemTag);
             $message->appendChild($messageText);
             $root->appendChild($message);
         }
         $root->appendChild($result);
         $root->appendChild($code);
         $root->appendChild($status);
         $this->buildXml($root, $response->data);
         $response->content = $dom->saveXML();
     }
 }
开发者ID:bolom009,项目名称:staging,代码行数:48,代码来源:XmlResponseFormatter.php

示例11: send

 protected function send($method, $path, $options)
 {
     list($url, $headers, $body) = $this->buildRequest($path, $options);
     $curl = $this->getCurlHandle();
     curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_VERBOSE, !!$this->debug);
     if ($this->debug) {
         curl_setopt($curl, CURLOPT_STDERR, is_string($this->debug) ? fopen($this->debug, "a+") : STDOUT);
     }
     curl_setopt($curl, CURLOPT_HEADER, true);
     switch ($method) {
         case 'PUT':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
             curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
             break;
         case 'DELETE':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         case 'POST':
             curl_setopt($curl, CURLOPT_POST, true);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
             break;
         case 'GET':
             curl_setopt($curl, CURLOPT_HTTPGET, true);
             break;
     }
     $raw_request_headers = [];
     foreach ($headers as $key => $value) {
         $raw_request_headers[] = "{$key}: {$value}";
     }
     curl_setopt($curl, CURLOPT_HTTPHEADER, $raw_request_headers);
     curl_setopt($curl, CURLOPT_URL, $url);
     $result = curl_exec($curl);
     $curl_info = curl_getinfo($curl);
     list($header, $body) = explode("\r\n\r\n", $result, 2);
     if ($body && $this->debug) {
         if (is_string($this->debug)) {
             error_log("{$body}\n", 3, $this->debug);
         } else {
             fwrite(is_resource($this->debug) ? $this->debug : STDOUT, "{$body}\n");
         }
     }
     $response = new Response($header, $body, $curl_info);
     if ($this->http_errors && $response->getStatusCode() >= 400) {
         $exception = new BadResponseException();
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
开发者ID:sendworks,项目名称:sendworks-php,代码行数:53,代码来源:Client.php

示例12: filterResponse

    /**
     * Converts the HttpKernel response to a BrowserKit response.
     *
     * @param Response $response A Response instance
     *
     * @return Response A Response instance
     */
    protected function filterResponse($response)
    {
        $headers = $response->headers->all();
        if ($response->headers->getCookies()) {
            $cookies = array();
            foreach ($response->headers->getCookies() as $cookie) {
                $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
            }
            $headers['Set-Cookie'] = $cookies;
        }

        // this is needed to support StreamedResponse
        ob_start();
        $response->sendContent();
        $content = ob_get_clean();

        return new DomResponse($content, $response->getStatusCode(), $headers);
    }
开发者ID:nysander,项目名称:symfony,代码行数:25,代码来源:Client.php

示例13: replaceSubmission

 /**
  *
  * @param TiiSubmission $submission
  */
 public function replaceSubmission($submission)
 {
     $params_merge = $this->getResubmissionFormHash($submission);
     if (is_null($submission->getSubmissionDataPath()) && is_null($submission->getSubmissionDataUrl())) {
         $params_merge['custom_submission_data'] = $submission->getSubmissionDataText();
     } else {
         if (is_null($submission->getSubmissionDataUrl())) {
             // CURL uploading with @ has been deprecated in PHP 5.5
             if (class_exists('CURLFile')) {
                 $finfo = new finfo(FILEINFO_MIME);
                 $mimetype = $finfo->file($submission->getSubmissionDataPath());
                 $params_merge['custom_submission_data'] = new CurlFile($submission->getSubmissionDataPath(), $mimetype);
             } else {
                 $params_merge['custom_submission_data'] = '@' . $submission->getSubmissionDataPath();
             }
         }
     }
     $transport = $this->transportData($params_merge);
     $response = new Response($this);
     if ($response->getStatusCode() == 'failure') {
         throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
     } else {
         $dom = $response->getDomObject();
         $tiiSubmission = new TiiSubmission();
         $tiiSubmission->setSubmissionId($dom->getElementsByTagName('lis_result_sourcedid')->item(0)->nodeValue);
         $tiiSubmission->setTextExtract(@$dom->getElementsByTagName('submission_data_extract')->item(0)->nodeValue);
         $response->setSubmission($tiiSubmission);
     }
     return $response;
 }
开发者ID:SkylarKelty,项目名称:moodle-mod_turnitintooltwo,代码行数:34,代码来源:lti.class.php

示例14: encodeResponse

 /**
  * {@inheritdoc}
  */
 public function encodeResponse(Response $response) : string
 {
     return sprintf("HTTP/%s %d %s\r\n%s\r\n", $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase(), $this->encodeHeaders($response->getHeaders()));
 }
开发者ID:icicleio,项目名称:http,代码行数:7,代码来源:Http1Encoder.php

示例15: testReturnsStatusCode

 public function testReturnsStatusCode()
 {
     $response = new Response('', 201);
     $this->assertSame(201, $response->getStatusCode());
 }
开发者ID:netrivet,项目名称:wp-http,代码行数:5,代码来源:ResponseTest.php


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