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


PHP Response::isSuccessful方法代码示例

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


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

示例1: filter

    /**
     * 
     *
     * @param Event $event An Event instance
     */
    public function filter(Event $event, Response $response)
    {
        if (!$configuration = $event->get('request')->attributes->get('_cache')) {
            return $response;
        }

        if (!$response->isSuccessful()) {
            return $response;
        }

        if (null !== $configuration->getSMaxAge()) {
            $response->setSharedMaxAge($configuration->getSMaxAge());
        }

        if (null !== $configuration->getMaxAge()) {
            $response->setMaxAge($configuration->getMaxAge());
        }

        if (null !== $configuration->getExpires()) {
            $date = \DateTime::create(\DateTime::createFromFormat('U', $configuration->getExpires(), new \DateTimeZone('UTC')));

            $response->setLastModified($date);
        }

        return $response;
    }
开发者ID:ruudk,项目名称:FrameworkExtraBundle,代码行数:31,代码来源:AnnotationCacheListener.php

示例2: formatData

 private function formatData(Response $response)
 {
     if (!$response->isSuccessful()) {
         // Response will have an exception attached
         if ($response instanceof LaravelResponse && $response->exception instanceof Exception) {
             return $this->formatException($response->exception);
         }
     }
     $content = $response->getContent();
     return $response instanceof JsonResponse ? json_decode($content) : $content;
 }
开发者ID:etorofiev,项目名称:laravel-batch-request,代码行数:11,代码来源:OptimusResultFormatter.php

示例3: isSuccessful

 protected function isSuccessful(HttpResponse $response)
 {
     if ($response->isSuccessful()) {
         if (false !== strpos($response->headers->get('Content-Type'), 'text/html')) {
             if (preg_match('/form\\s+name="login_form"\\s+action="([^"]+)"/mi', $response->getContent(), $match)) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
开发者ID:lrusev,项目名称:bump-common,代码行数:12,代码来源:PDCApiBase.php

示例4: getParameters

 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     $code = null;
     $codeType = null;
     $cacheable = null;
     if (null !== $this->response) {
         $code = sprintf('%d', $this->response->getStatusCode());
         $cacheable = $this->response->isCacheable() ? 'cacheable' : 'not_cacheable';
         if ($this->response->isInformational()) {
             $codeType = 'informational';
         } elseif ($this->response->isSuccessful()) {
             $codeType = 'successful';
         } elseif ($this->response->isRedirection()) {
             $codeType = 'redirection';
         } elseif ($this->response->isClientError()) {
             $codeType = 'client_error';
         } elseif ($this->response->isServerError()) {
             $codeType = 'server_error';
         } else {
             $codeType = 'other';
         }
     }
     return array('response_code' => $code, 'response_code_type' => $codeType, 'response_cacheable' => $cacheable);
 }
开发者ID:adrienbrault,项目名称:statsd-collector,代码行数:27,代码来源:SymfonyResponseProvider.php

示例5: shouldCacheResponse

 /**
  * Determine if the given response should be cached.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  *
  * @return bool
  */
 public function shouldCacheResponse(Response $response)
 {
     return $response->isSuccessful() || $response->isRedirection();
 }
开发者ID:zedx,项目名称:core,代码行数:11,代码来源:CacheProfile.php

示例6: testIsSuccessful

 public function testIsSuccessful()
 {
     $response = new Response();
     $this->assertTrue($response->isSuccessful());
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:5,代码来源:ResponseTest.php

示例7: deliver

 /**
  * Delivers the Response as a string.
  *
  * When the Response is a StreamedResponse, the content is streamed immediately
  * instead of being returned.
  *
  * @param Response $response A Response instance
  *
  * @return string|null The Response content or null when the Response is streamed
  *
  * @throws \RuntimeException when the Response is not successful
  */
 protected function deliver(Response $response)
 {
     if (!$response->isSuccessful()) {
         throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requests[0]->getUri(), $response->getStatusCode()));
     }
     if (!$response instanceof StreamedResponse) {
         return $response->getContent();
     }
     $response->sendContent();
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:22,代码来源:FragmentHandler.php

示例8: isSuccessful

 /**
  * Checks the success state of a response.
  *
  * @param Response $response Response object
  * @param bool     $success  to define whether the response is expected to be successful
  * @param string   $type
  */
 public function isSuccessful(Response $response, $success = true, $type = 'text/html')
 {
     try {
         $crawler = new Crawler();
         $crawler->addContent($response->getContent(), $type);
         if (!count($crawler->filter('title'))) {
             $title = '[' . $response->getStatusCode() . '] - ' . $response->getContent();
         } else {
             $title = $crawler->filter('title')->text();
         }
     } catch (\Exception $e) {
         $title = $e->getMessage();
     }
     if ($success) {
         $this->assertTrue($response->isSuccessful(), 'The Response was not successful: ' . $title);
     } else {
         $this->assertFalse($response->isSuccessful(), 'The Response was successful: ' . $title);
     }
 }
开发者ID:TIFU124,项目名称:LiipFunctionalTestBundle,代码行数:26,代码来源:WebTestCase.php

示例9: isCacheable

 /**
  * @param Request $request
  * @param Response $response
  *
  * @return bool|int Will return integer code if response cannot be cached or true if it's cacheable
  */
 public function isCacheable(Request $request, Response $response)
 {
     if ($request->attributes->get('_supercache') === false) {
         return CacheManager::UNCACHEABLE_ROUTE;
     }
     if ($request->getMethod() !== 'GET') {
         return CacheManager::UNCACHEABLE_METHOD;
     }
     $queryString = $request->server->get('QUERY_STRING');
     if (!empty($queryString)) {
         return CacheManager::UNCACHEABLE_QUERY;
     }
     //Response::isCacheable() is unusable here due to expiry & code settings
     if (!$response->isSuccessful() || $response->isEmpty()) {
         return CacheManager::UNCACHEABLE_CODE;
     }
     if ($response->headers->hasCacheControlDirective('no-store')) {
         return CacheManager::UNCACHEABLE_NO_STORE_POLICY;
     }
     if ($response->headers->hasCacheControlDirective('private')) {
         return CacheManager::UNCACHEABLE_PRIVATE;
     }
     $environment = $this->container->getParameter('kernel.environment');
     if ($environment !== 'prod' && $environment !== 'dev' || !$this->container->getParameter('supercache.enable_' . $environment)) {
         return CacheManager::UNCACHEABLE_ENVIRONMENT;
     }
     return true;
 }
开发者ID:kiler129,项目名称:SupercacheBundle,代码行数:34,代码来源:ResponseHandler.php

示例10: showErrorInBrowserIfOccurred

 /**
  * @param Response $response
  *
  * @throws \Exception
  */
 protected function showErrorInBrowserIfOccurred(Response $response)
 {
     if (!$response->isSuccessful()) {
         $openCommand = isset($_SERVER['OPEN_BROWSER_COMMAND']) ? $_SERVER['OPEN_BROWSER_COMMAND'] : 'open %s';
         $filename = rtrim(sys_get_temp_dir(), \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR . uniqid() . '.html';
         file_put_contents($filename, $response->getContent());
         system(sprintf($openCommand, escapeshellarg($filename)));
         throw new \Exception('Internal server error.');
     }
 }
开发者ID:steffenbrem,项目名称:ApiTestCase,代码行数:15,代码来源:ApiTestCase.php

示例11: isSuccessful

 protected function isSuccessful(HttpResponse $response)
 {
     return $response->isSuccessful();
 }
开发者ID:lrusev,项目名称:bump-common,代码行数:4,代码来源:Base.php

示例12: assertSuccessfulResponse

 public function assertSuccessfulResponse(Response $response)
 {
     $this->assertTrue($response->isSuccessful());
 }
开发者ID:eugene-matvejev,项目名称:battleship-game-api,代码行数:4,代码来源:ResponseAssertionSuites.php

示例13: store

 /**
  * Store successful responses with the cache resolver.
  *
  * @see ResolverInterface::store
  *
  * @param Response $response
  * @param string $targetPath
  * @param string $filter
  *
  * @return Response
  */
 public function store(Response $response, $targetPath, $filter)
 {
     if ($response->isSuccessful()) {
         $response = $this->getResolver($filter)->store($response, $targetPath, $filter);
     }
     return $response;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:18,代码来源:CacheManager.php

示例14: deliverResponse

 /**
  * Deliver response
  *
  * @param Request $request
  * @param Response $response
  *
  * @return string
  */
 protected function deliverResponse(Request $request, Response $response)
 {
     if (!$response->isSuccessful()) {
         throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $request->getUri(), $response->getStatusCode()));
     }
     return $response->getContent();
 }
开发者ID:makinacorpus,项目名称:drupal-sf-dic,代码行数:15,代码来源:HttpRenderExtension.php

示例15: assertSuccessResponse

 protected function assertSuccessResponse($expected, Response $response)
 {
     $this->assertTrue($response->isSuccessful(), 'request is successful');
     $this->assertJson($response->getContent(), 'response is json');
     $this->assertJsonResponse($expected, $response);
 }
开发者ID:JeroenDeDauw,项目名称:QueryrAPI,代码行数:6,代码来源:ApiTestCase.php


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