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


PHP Response::getStatusCode方法代码示例

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


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

示例1: assertSuccess

 public function assertSuccess()
 {
     if ($this->response->getStatusCode() != 200) {
         $this->fail($this->response->getContent());
     }
     return $this;
 }
开发者ID:yasoon,项目名称:yasoon,代码行数:7,代码来源:AuthControllerTest.php

示例2: testUnspecified

 public function testUnspecified()
 {
     $this->mapping->setParameter('missing');
     $this->action->execute($this->mapping, null, $this->request, $this->response);
     $this->assertNotEmpty($this->response->getContent());
     $this->assertEquals(400, $this->response->getStatusCode());
 }
开发者ID:cammanderson,项目名称:phruts,代码行数:7,代码来源:ActionDispatcherTest.php

示例3: parseNonPhtml

 public static function parseNonPhtml(Response $response, $file)
 {
     if (!file_exists($file = file_exists($file = self::getPath() . $file) ? $file : (file_exists($file . '.html') ? $file . '.html' : (file_exists($file . '.xhtml') ? $file . '.xhtml' : (file_exists($file . '.php') ? $file . '.php' : $file))))) {
         if ($response->getStatusCode() == 200) {
             $response->setStatusCode(404);
         }
         $response->setContent($file = (string) new Phtml('/errors/' . $response->getStatusCode(), FALSE, 'default'));
     } else {
         if (strpos($file = realpath($file), realpath(Skin::getPath())) !== 0) {
             throw new \Exception('Unknown skin path: "' . $file . '".');
         }
         $file = str_replace('sitemap.xml.php', 'sitemap.xml', $file);
         $repository = new PhpRepository();
         $response->headers->set('Content-Type', $repository->findType(strtolower(substr(strrchr($file, '.'), 1)) ?: $file) ?: 'text/plain');
         if (basename($file) == 'sitemap.xml') {
             $phtml = new Phtml(NULL);
             $file = $phtml->parsePhtml($file . '.php');
         } else {
             $file = file_get_contents($file);
         }
         $response->setContent($file);
     }
     $response->headers->set('Cache-Control', 'max-age=604800');
     $response->headers->set('Content-Length', strlen($file));
     return $response;
 }
开发者ID:RobbiNespu,项目名称:php-proxy-keyserver,代码行数:26,代码来源:Skin.php

示例4: getStatusCode

 /**
  * @return int
  */
 public function getStatusCode()
 {
     if ($this->response === null) {
         return null;
     }
     return $this->response->getStatusCode();
 }
开发者ID:ndrx-io,项目名称:profiler,代码行数:10,代码来源:Http.php

示例5: logResponse

 /**
  * Logs a response
  *
  * @param Response $response
  */
 protected function logResponse(Response $response)
 {
     if ($response instanceof RedirectResponse) {
         $this->logger->info('< ' . $response->getStatusCode() . ' ' . $response->getTargetUrl());
     } else {
         $this->logger->info('< ' . $response->getStatusCode());
     }
 }
开发者ID:hafedhbou,项目名称:hetic-p2017,代码行数:13,代码来源:LogListener.php

示例6: logResponse

 /**
  * @param \Symfony\Component\HttpFoundation\Response $response
  *
  * @return void
  */
 protected function logResponse(Response $response)
 {
     if ($response instanceof RedirectResponse) {
         $message = sprintf('%s Response %s [%s], target URL %s', $this->getSapi(), APPLICATION, $response->getStatusCode(), $response->getTargetUrl());
     } else {
         $message = sprintf('%s Response %s [%s]', $this->getSapi(), APPLICATION, $response->getStatusCode());
     }
     $this->logger->info($message, ['response' => $response]);
 }
开发者ID:spryker,项目名称:Application,代码行数:14,代码来源:KernelLogListener.php

示例7: adaptResponse

 /**
  * @param InternalResponse $iResponse
  * @return Response
  */
 public function adaptResponse(InternalResponse $iResponse)
 {
     $response = new Response($iResponse->getContent(), $iResponse->getStatusCode(), $iResponse->getHeaders());
     if ($this->request) {
         $response->prepare($this->request);
     }
     if ($response->getStatusCode() !== 200) {
         $response->setContent(Response::$statusTexts[$response->getStatusCode()]);
         return $response;
     }
     return $response;
 }
开发者ID:kankje,项目名称:xi-filelib,代码行数:16,代码来源:SymfonyRendererAdapter.php

示例8: collect

    /**
     * {@inheritdoc}
     */
    public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $responseHeaders = $response->headers->all();
        $cookies = array();
        foreach ($response->headers->getCookies() as $cookie) {
            $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
        }
        if (count($cookies) > 0) {
            $responseHeaders['Set-Cookie'] = $cookies;
        }

        $attributes = array();
        foreach ($request->attributes->all() as $key => $value) {
            $attributes[$key] = is_object($value) ? sprintf('Object(%s)', get_class($value)) : $value;
        }

        $this->data = array(
            'format'             => $request->getRequestFormat(),
            'content_type'       => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html',
            'status_code'        => $response->getStatusCode(),
            'request_query'      => $request->query->all(),
            'request_request'    => $request->request->all(),
            'request_headers'    => $request->headers->all(),
            'request_server'     => $request->server->all(),
            'request_cookies'    => $request->cookies->all(),
            'request_attributes' => $attributes,
            'response_headers'   => $responseHeaders,
            'session_attributes' => $request->hasSession() ? $request->getSession()->getAttributes() : array(),
        );
    }
开发者ID:Gregwar,项目名称:symfony,代码行数:33,代码来源:RequestDataCollector.php

示例9: serialize

 /**
  * Serialize a response.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  *
  * @return string
  */
 public function serialize(Response $response)
 {
     $content = $response->getContent();
     $statusCode = $response->getStatusCode();
     $headers = $response->headers;
     return serialize(compact('content', 'statusCode', 'headers'));
 }
开发者ID:zedx,项目名称:core,代码行数:14,代码来源:ResponseSerializer.php

示例10: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $responseHeaders = $response->headers->all();
     $cookies = array();
     foreach ($response->headers->getCookies() as $cookie) {
         $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
     }
     if (count($cookies) > 0) {
         $responseHeaders['Set-Cookie'] = $cookies;
     }
     $attributes = array();
     foreach ($request->attributes->all() as $key => $value) {
         if (is_object($value)) {
             $attributes[$key] = sprintf('Object(%s)', get_class($value));
             if (is_callable(array($value, '__toString'))) {
                 $attributes[$key] .= sprintf(' = %s', (string) $value);
             }
         } else {
             $attributes[$key] = $value;
         }
     }
     $content = null;
     try {
         $content = $request->getContent();
     } catch (\LogicException $e) {
         // the user already got the request content as a resource
         $content = false;
     }
     $this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(), 'path_info' => $request->getPathInfo());
 }
开发者ID:netcon-source,项目名称:prontotype,代码行数:33,代码来源:RequestDataCollector.php

示例11: getMessage

 private function getMessage(Response $response)
 {
     if (500 >= $response->getStatusCode() && $response->getStatusCode() < 600) {
         $crawler = new Crawler();
         $crawler->addHtmlContent($response->getContent());
         if ($crawler->filter('.text-exception h1')->count() > 0) {
             $exceptionMessage = trim($crawler->filter('.text-exception h1')->text());
             $trace = '';
             if ($crawler->filter('#traces-0 li')->count() > 0) {
                 list($trace) = explode("\n", trim($crawler->filter('#traces-0 li')->text()));
             }
             return $message = 'Internal Server Error: ' . $exceptionMessage . ' ' . $trace;
         }
     }
     return $response->getContent();
 }
开发者ID:detain,项目名称:PayumServer,代码行数:16,代码来源:ResponseHelper.php

示例12: assertJsonResponse

 /**
  * Test API response status
  *
  * @param Response $response
  * @param int    $statusCode
  * @param string $contentType
  */
 public static function assertJsonResponse($response, $statusCode = 201, $contentType = 'application/json')
 {
     \PHPUnit_Framework_TestCase::assertEquals($statusCode, $response->getStatusCode(), $response->getContent());
     if ($contentType !== '') {
         \PHPUnit_Framework_TestCase::assertTrue($response->headers->contains('Content-Type', $contentType), $response->headers);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:14,代码来源:ToolsAPI.php

示例13: assertJsonResponse

 /**
  * @param Response $response
  * @param int      $statusCode
  * @param bool     $checkValidJson
  * @param string   $contentType
  * @return array   Json decoded
  */
 protected function assertJsonResponse(Response $response, $statusCode = 200, $checkValidJson = true, $contentType = 'application/json')
 {
     $content = null;
     $this->assertEquals($statusCode, $response->getStatusCode(), sprintf("Status code is not expected %d, got %d instead\n%s", $statusCode, $response->getStatusCode(), $response->getContent()));
     // If content-type is an URL, check for Location header (DELETE)
     if (strpos($contentType, '://') === false) {
         $this->assertTrue($response->headers->contains('Content-Type', $contentType), sprintf('No "Content-Type" header set to %s', $contentType));
     } else {
         $this->assertTrue($response->headers->contains('Location', $contentType), sprintf('No "Location" header set to %s', $contentType));
     }
     if ($checkValidJson) {
         $content = json_decode($response->getContent(), true);
         $this->assertTrue($content !== null && $content !== false, 'is response valid json: [' . $response->getContent() . ']');
     }
     return $content;
 }
开发者ID:phpink,项目名称:nami-core-bundle,代码行数:23,代码来源:ApiTestCase.php

示例14: handle

 /**
  * @param HTTPApiClient $apiClient
  * @param Response      $response
  * @param ClientRequest $clientRequest
  * @return mixed
  */
 public function handle(HTTPApiClient $apiClient, Response $response, ClientRequest $clientRequest)
 {
     if (200 != $response->getStatusCode()) {
         $e = new BadResponseException();
         $this->throwException($e, $response, $clientRequest);
     }
 }
开发者ID:xjtuwangke,项目名称:laravel-bundles,代码行数:13,代码来源:BadResponseMiddleware.php

示例15: assertForm

 /**
  * @param Response $response
  */
 protected function assertForm(Response $response)
 {
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertRegExp('/form/', $response->getContent());
     $this->assertNotRegExp('/<html/', $response->getContent());
     $this->assertNotRegExp('/_username/', $response->getContent());
 }
开发者ID:open-orchestra,项目名称:open-orchestra,代码行数:10,代码来源:AbstractFormTest.php


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