isSuccessful() публичный Метод

Is response successful?
public isSuccessful ( ) : boolean
Результат boolean
    /**
     * 
     *
     * @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;
    }
 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;
 }
Пример #3
0
 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;
 }
 /**
  * {@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);
 }
Пример #5
0
 /**
  * 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();
 }
Пример #6
0
 public function testIsSuccessful()
 {
     $response = new Response();
     $this->assertTrue($response->isSuccessful());
 }
Пример #7
0
 /**
  * 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();
 }
 /**
  * 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);
     }
 }
Пример #9
0
 /**
  * @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;
 }
Пример #10
0
 /**
  * @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.');
     }
 }
Пример #11
0
 protected function isSuccessful(HttpResponse $response)
 {
     return $response->isSuccessful();
 }
 public function assertSuccessfulResponse(Response $response)
 {
     $this->assertTrue($response->isSuccessful());
 }
Пример #13
0
 /**
  * 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;
 }
 /**
  * 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();
 }
Пример #15
0
 protected function assertSuccessResponse($expected, Response $response)
 {
     $this->assertTrue($response->isSuccessful(), 'request is successful');
     $this->assertJson($response->getContent(), 'response is json');
     $this->assertJsonResponse($expected, $response);
 }