當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。