本文整理汇总了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());
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例7: testSetClientTtl
public function testSetClientTtl()
{
$response = new Response();
$response->setClientTtl(10);
$this->assertEquals($response->getMaxAge(), $response->getAge() + 10);
}
示例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);
}