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


PHP Response::isOk方法代码示例

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


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

示例1: handleResponse

 /**
  * Update a valid non cacheable Response with http cache headers
  *
  * @see http://symfony.com/fr/doc/current/book/http_cache.html
  */
 public function handleResponse(Response $response)
 {
     // do not handle invalid response
     if (!$response->isOk()) {
         return $response;
     }
     // do not handle response with http cache headers
     if ($response->isCacheable()) {
         return $response;
     }
     // seek for optional configuration
     $this->readRoutingConfiguration();
     // mark the response as private
     $response->setPrivate();
     // set the private or shared max age
     $response->setMaxAge($this->duration);
     $response->setSharedMaxAge($this->duration);
     // set expires
     $date = new \DateTime();
     $date->modify(sprintf('+%d seconds', $this->duration));
     $response->setExpires($date);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     return $response;
 }
开发者ID:kmelia,项目名称:fresh-symfony,代码行数:30,代码来源:HttpCacheResponseHandler.php

示例2: setDetails

 /**
  * Parses the requested route to fetch
  * - the resource (databox, basket, record etc ..)
  * - general action (list, add, search)
  * - the action (setstatus, setname etc..)
  * - the aspect (collections, related, content etc..)
  *
  * @param ApiLog   $log
  * @param Request  $request
  * @param Response $response
  */
 private function setDetails(ApiLog $log, Request $request, Response $response)
 {
     $chunks = explode('/', trim($request->getPathInfo(), '/'));
     if (false === $response->isOk() || sizeof($chunks) === 0) {
         return;
     }
     switch ($chunks[0]) {
         case ApiLog::DATABOXES_RESOURCE:
             $this->hydrateDataboxes($log, $chunks);
             break;
         case ApiLog::RECORDS_RESOURCE:
             $this->hydrateRecords($log, $chunks);
             break;
         case ApiLog::BASKETS_RESOURCE:
             $this->hydrateBaskets($log, $chunks);
             break;
         case ApiLog::FEEDS_RESOURCE:
             $this->hydrateFeeds($log, $chunks);
             break;
         case ApiLog::QUARANTINE_RESOURCE:
             $this->hydrateQuarantine($log, $chunks);
             break;
         case ApiLog::STORIES_RESOURCE:
             $this->hydrateStories($log, $chunks);
             break;
         case ApiLog::MONITOR_RESOURCE:
             $this->hydrateMonitor($log, $chunks);
             break;
     }
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:41,代码来源:ApiLogManipulator.php

示例3: after

 public function after(Request $request, Response $response)
 {
     $now = new \DateTime("now");
     $mapper = new CacheRecordSQLMapper($this->app["db"]);
     $currentRouteName = $request->attributes->get("_route");
     if ($this->isCacheCompromiser($currentRouteName)) {
         /** @todo method check */
         $mapper = new CacheRecordSQLMapper($this->app["db"]);
         $compromisedCount = $mapper->compromiseAll();
         return;
     }
     if ($this->isRouteCacheable($currentRouteName) && $response->isOk()) {
         $cacheRecord = $mapper->findByUri($this->getCurrentUri());
         if (!$cacheRecord) {
             //                $this->createCacheRecord();
             $data = [];
             $data["uri"] = $this->getCurrentUri();
             $data["hash"] = md5($response->getContent());
             $data["lmt"] = $now->format("Y-m-d H:i:s");
             $cacheRecord = new CacheRecord($data);
             $mapper->create($cacheRecord);
             $response->setPublic();
             $response->setDate($now);
             $response->setMaxAge($this->config->getMaxAge());
             $response->setSharedMaxAge($this->config->getMaxAgeShared());
             $response->setLastModified($now);
             $response->headers->addCacheControlDirective('must-revalidate', true);
             return $response;
         }
         if ($cacheRecord->getCompromised()) {
             if ($cacheRecord->getHash() === md5($response->getContent())) {
                 $cacheRecord->setCompromised(false);
                 $mapper->update($cacheRecord->getId(), $cacheRecord);
                 $response = $this->createResponse($cacheRecord->getLmt());
                 $response->setNotModified();
                 return $response;
             } else {
                 $cacheRecord->setCompromised(false);
                 $cacheRecord->setHash(md5($response->getContent()));
                 $cacheRecord->setLmt(date("Y-m-d H:i:s"));
                 $mapper->update($cacheRecord->getId(), $cacheRecord);
                 return $response;
             }
         } else {
             $now = new \DateTime("2015-12-12");
             $response->setPublic();
             $response->setDate($now);
             $response->setMaxAge($this->config->getMaxAge());
             $response->setSharedMaxAge($this->config->getMaxAgeShared() + 1);
             $response->setLastModified(new \DateTime($cacheRecord->getLmt()));
             return $response;
         }
     }
 }
开发者ID:konstantin-s,项目名称:silex-lazycache,代码行数:54,代码来源:LazyCache.php

示例4: afterRead

 public static function afterRead(Request $request, Response $response, Application $app)
 {
     if ($response->isOk()) {
         $token = self::getCacheToken($request, $app);
         if (!$app['cache']->contains($token)) {
             if (self::isFileListRequest($request)) {
                 $minutes = $app['config']->getMinutesCachingFileListings();
             } else {
                 $minutes = $app['config']->getMinutesCachingData();
             }
             $app['cache']->save($token, $response->getContent(), $minutes * 60);
         }
     }
 }
开发者ID:nhagemann,项目名称:anycontent-repository-mysql-php,代码行数:14,代码来源:ResponseCache.php

示例5: processResponse

 /**
  * {@inheritdoc}
  */
 public function processResponse(Request $request, Response $response)
 {
     if (!$response->isOk()) {
         return;
     }
     $cacheKey = $request->attributes->get('_cacheKey');
     $ttl = $request->attributes->get('_cacheTTL');
     if (empty($cacheKey)) {
         return;
     }
     $cache = $this->getCache();
     $this->info(sprintf('miss: save into cache: %s', $cacheKey), ['application' => 'cache', 'type' => 'miss', 'cacheKey' => $cacheKey, 'ttl' => $ttl]);
     $item = $cache->getItem($cacheKey);
     $item->set($response);
     $item->expiresAfter($ttl);
     $cache->save($item);
     $response->headers->set('X-Cache', 'miss');
     $response->setMaxAge($ttl);
     $response->setExpires(new DateTime(sprintf('+%d seconds', $ttl)));
 }
开发者ID:brainexe,项目名称:core,代码行数:23,代码来源:Cache.php

示例6: testIsOk

 public function testIsOk()
 {
     $response = new Response('', 200);
     $this->assertTrue($response->isOk());
     $response = new Response('', 404);
     $this->assertFalse($response->isOk());
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:7,代码来源:ResponseTest.php

示例7: assertResponseOk

 private function assertResponseOk(Response $response)
 {
     $this->assertTrue($response->isOk());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:5,代码来源:LazaretTest.php


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