當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::getAge方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\Response::getAge方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getAge方法的具體用法?PHP Response::getAge怎麽用?PHP Response::getAge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::getAge方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testUpdateResponse

 public function testUpdateResponse()
 {
     $this->response->setPublic()->shouldBeCalled();
     $this->response->setMaxAge($this->maxAge)->shouldBeCalled();
     $this->response->setSharedMaxAge($this->sharedMaxAge)->shouldBeCalled();
     $this->structure->getCacheLifeTime()->willReturn(10);
     $this->response->getAge()->willReturn(50);
     $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal());
 }
開發者ID:ollietb,項目名稱:sulu,代碼行數:9,代碼來源:PublicHandlerTest.php

示例2: updateResponse

 /**
  * {@inheritDoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + intval($structure->getCacheLifeTime()) : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
開發者ID:kriswillis,項目名稱:sulu,代碼行數:17,代碼來源:PublicHandler.php

示例3: getReverseProxyTtl

 /**
  * Returns the response reverse-proxy cache TTL in seconds.
  *
  * @param Response $response
  *
  * @return int|null The TTL in seconds
  */
 private function getReverseProxyTtl(Response $response)
 {
     if (null !== ($maxAge = $response->headers->get(self::HEADER_REVERSE_PROXY_TTL))) {
         return $maxAge - $response->getAge();
     }
     return;
 }
開發者ID:kriswillis,項目名稱:sulu,代碼行數:14,代碼來源:HttpCache.php

示例4: updateResponse

 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     $cacheLifetimeData = $structure->getCacheLifeTime();
     $cacheLifetime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']);
     // when structure cache-lifetime disabled - return
     if (0 === $cacheLifetime) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + $cacheLifetime : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
開發者ID:sulu,項目名稱:sulu,代碼行數:23,代碼來源:PublicHandler.php

示例5: indexAction

 /**
  * Returns a rendered xmlsitemap.
  *
  * @return Response
  */
 public function indexAction(Request $request)
 {
     /** @var RequestAnalyzerInterface $requestAnalyzer */
     $requestAnalyzer = $this->get('sulu_core.webspace.request_analyzer');
     /** @var SitemapXMLGeneratorInterface $sitemapXMLGenerator */
     $sitemapXMLGenerator = $this->get('sulu_website.sitemap_xml_generator');
     $sitemap = $this->get('sulu_content.content_repository')->findAll($requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), $requestAnalyzer->getWebspace()->getKey(), MappingBuilder::create()->addProperties(['changed'])->setResolveUrl(true)->getMapping());
     $webspaceSitemaps = [['localizations' => array_map(function (Localization $localization) {
         return $localization->getLocalization();
     }, $requestAnalyzer->getWebspace()->getAllLocalizations()), 'defaultLocalization' => $requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), 'sitemap' => $sitemap]];
     $preferredDomain = $request->getHttpHost();
     // XML Response
     $response = new Response();
     $response->setMaxAge(240);
     $response->setSharedMaxAge(960);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($sitemapXMLGenerator->generate($webspaceSitemaps, $preferredDomain, $request->getScheme()));
     // Generate XML
     return $response;
 }
開發者ID:Silwereth,項目名稱:sulu,代碼行數:26,代碼來源:SitemapController.php

示例6: indexAction

 /**
  * Returns a rendered xmlsitemap.
  *
  * @return Response
  */
 public function indexAction(Request $request)
 {
     /** @var RequestAnalyzerInterface $requestAnalyzer */
     $requestAnalyzer = $this->get('sulu_core.webspace.request_analyzer');
     /** @var SitemapGeneratorInterface $sitemapGenerator */
     $sitemapGenerator = $this->get('sulu_website.sitemap');
     /** @var SitemapXMLGeneratorInterface $sitemapXMLGenerator */
     $sitemapXMLGenerator = $this->get('sulu_website.sitemap_xml_generator');
     $flatSitemap = true;
     $webspaceSitemaps = [$sitemapGenerator->generateAllLocals($requestAnalyzer->getWebspace()->getKey(), $flatSitemap)];
     $preferredDomain = $request->getHttpHost();
     // XML Response
     $response = new Response();
     $response->setMaxAge(240);
     $response->setSharedMaxAge(960);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($sitemapXMLGenerator->generate($webspaceSitemaps, $preferredDomain));
     // Generate XML
     return $response;
 }
開發者ID:ollietb,項目名稱:sulu,代碼行數:26,代碼來源:SitemapController.php

示例7: testSetClientTtl

 public function testSetClientTtl()
 {
     $response = new Response();
     $response->setClientTtl(10);
     $this->assertEquals($response->getMaxAge(), $response->getAge() + 10);
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:6,代碼來源:ResponseTest.php

示例8: setCacheLifetime

 /**
  * Set cache headers.
  *
  * @param Response $response
  *
  * @return Response
  */
 private function setCacheLifetime(Response $response)
 {
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     return $response->setMaxAge(240)->setSharedMaxAge(960);
 }
開發者ID:sulu,項目名稱:sulu,代碼行數:12,代碼來源:SitemapController.php


注:本文中的Symfony\Component\HttpFoundation\Response::getAge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。