本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::getMaxAge方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getMaxAge方法的具体用法?PHP Response::getMaxAge怎么用?PHP Response::getMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::getMaxAge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMaxAge
/**
* @return int
*/
protected function getMaxAge()
{
if ($this->response === null) {
return null;
}
return $this->response->getMaxAge();
}
示例2: update
/**
* {@inheritdoc}
*/
public function update(Response $response)
{
// if we have no embedded Response, do nothing
if (0 === $this->embeddedResponses) {
return;
}
// Remove validation related headers in order to avoid browsers using
// their own cache, because some of the response content comes from
// at least one embedded response (which likely has a different caching strategy).
if ($response->isValidateable()) {
$response->setEtag(null);
$response->setLastModified(null);
$this->cacheable = false;
}
if (!$this->cacheable) {
$response->headers->set('Cache-Control', 'no-cache, must-revalidate');
return;
}
$this->ttls[] = $response->getTtl();
$this->maxAges[] = $response->getMaxAge();
if (null !== ($maxAge = min($this->maxAges))) {
$response->setSharedMaxAge($maxAge);
$response->headers->set('Age', $maxAge - min($this->ttls));
}
$response->setMaxAge(0);
}
示例3: add
/**
* Adds a Response.
*
* @param Response $response
*/
public function add(Response $response)
{
if ($response->isValidateable()) {
$this->cacheable = false;
} else {
$this->ttls[] = $response->getTtl();
$this->maxAges[] = $response->getMaxAge();
}
}
示例4: testGetMaxAge
public function testGetMaxAge()
{
$response = new Response();
$response->headers->set('Cache-Control', 's-maxage=600, max-age=0');
$this->assertEquals(600, $response->getMaxAge(), '->getMaxAge() uses s-maxage cache control directive when present');
$response = new Response();
$response->headers->set('Cache-Control', 'max-age=600');
$this->assertEquals(600, $response->getMaxAge(), '->getMaxAge() falls back to max-age when no s-maxage directive present');
$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');
$response = new Response();
$this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available');
}
示例5: logResponse
protected function logResponse(Response $response, Request $request)
{
if ($response->getStatusCode() >= 500) {
$color = LogLevel::ERROR;
} elseif ($response->getStatusCode() >= 400) {
$color = LogLevel::WARNING;
} elseif ($response->getStatusCode() >= 300) {
$color = LogLevel::NOTICE;
} elseif ($response->getStatusCode() >= 200) {
$color = LogLevel::INFO;
} else {
$color = LogLevel::INFO;
}
$msg = 'Response {response_status_code} for "{request_method} {request_uri}"';
$context = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary());
$this->logger->log($color, $msg, $context);
}
示例6: getAction
/**
* Send a media stored via the UploadedFileManager
*
* @Config\Route("/{key}", name="open_orchestra_media_get")
* @Config\Method({"GET"})
*
* @return Response
*/
public function getAction($key)
{
$mediaStorageManager = $this->get('open_orchestra_media_file.manager.storage');
$fileContent = $mediaStorageManager->getFileContent($key);
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_buffer($finfo, $fileContent);
finfo_close($finfo);
$response = new Response();
$response->headers->set('Content-Type', $mimetype);
$response->headers->set('Content-Length', strlen($fileContent));
$response->setContent($fileContent);
$response->setPublic();
$response->setMaxAge(2629743);
$date = new \DateTime();
$date->modify('+' . $response->getMaxAge() . ' seconds');
$response->setExpires($date);
return $response;
}
示例7: testSetCache
public function testSetCache()
{
$response = new Response();
//array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public')
try {
$response->setCache(array("wrong option" => "value"));
$this->fail('->setCache() throws an InvalidArgumentException if an option is not supported');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->setCache() throws an InvalidArgumentException if an option is not supported');
$this->assertContains('"wrong option"', $e->getMessage());
}
$options = array('etag' => '"whatever"');
$response->setCache($options);
$this->assertEquals($response->getEtag(), '"whatever"');
$now = new \DateTime();
$options = array('last_modified' => $now);
$response->setCache($options);
$this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp());
$options = array('max_age' => 100);
$response->setCache($options);
$this->assertEquals($response->getMaxAge(), 100);
$options = array('s_maxage' => 200);
$response->setCache($options);
$this->assertEquals($response->getMaxAge(), 200);
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('public' => true));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('public' => false));
$this->assertFalse($response->headers->hasCacheControlDirective('public'));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('private' => true));
$this->assertFalse($response->headers->hasCacheControlDirective('public'));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('private' => false));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
}
示例8: createContext
/**
* @param Response $response
* @param Request $request
*
* @return array
*/
protected function createContext(Response $response, Request $request)
{
$context = array('response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary(), 'request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'response_time' => $this->getTime($request), 'response_memory' => $this->getMemory());
return $context;
}