当前位置: 首页>>代码示例>>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;未经允许,请勿转载。