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


PHP Response::getMaxAge方法代码示例

本文整理汇总了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();
 }
开发者ID:ndrx-io,项目名称:profiler,代码行数:10,代码来源:Http.php

示例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);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:29,代码来源:ResponseCacheStrategy.php

示例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();
     }
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:14,代码来源:EsiResponseCacheStrategy.php

示例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');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:15,代码来源:ResponseTest.php

示例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);
 }
开发者ID:caxy,项目名称:drupal-console-logging-middleware,代码行数:17,代码来源:RequestLoggingMiddleware.php

示例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;
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-file-bundle,代码行数:26,代码来源:MediaController.php

示例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'));
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:39,代码来源:ResponseTest.php

示例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;
 }
开发者ID:Hexanet,项目名称:MonologExtraBundle,代码行数:11,代码来源:ResponseLogger.php


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