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


PHP Response::setExpires方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setExpires方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setExpires方法的具体用法?PHP Response::setExpires怎么用?PHP Response::setExpires使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::setExpires方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleResponse

 /**
  * Update a valid non cacheable Response with http cache headers
  *
  * @see http://symfony.com/fr/doc/current/book/http_cache.html
  */
 public function handleResponse(Response $response)
 {
     // do not handle invalid response
     if (!$response->isOk()) {
         return $response;
     }
     // do not handle response with http cache headers
     if ($response->isCacheable()) {
         return $response;
     }
     // seek for optional configuration
     $this->readRoutingConfiguration();
     // mark the response as private
     $response->setPrivate();
     // set the private or shared max age
     $response->setMaxAge($this->duration);
     $response->setSharedMaxAge($this->duration);
     // set expires
     $date = new \DateTime();
     $date->modify(sprintf('+%d seconds', $this->duration));
     $response->setExpires($date);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     return $response;
 }
开发者ID:kmelia,项目名称:fresh-symfony,代码行数:30,代码来源:HttpCacheResponseHandler.php

示例2: cacheResponse

 /**
  * Cache the response 1 year (31536000 sec)
  */
 protected function cacheResponse(Response $response)
 {
     $response->setSharedMaxAge(31536000);
     $response->setMaxAge(31536000);
     $response->setExpires(new \DateTime('+1 year'));
     return $response;
 }
开发者ID:Vrian7ipx,项目名称:repocas,代码行数:10,代码来源:AssetController.php

示例3: hellaAction

 /**
  * @Route("/routeC")
  */
 public function hellaAction()
 {
     $date = new \DateTime();
     $date->modify('+5 seconds');
     $response = new Response('');
     $response->setExpires($date);
 }
开发者ID:rouffj,项目名称:rouffj-test,代码行数:10,代码来源:FooController.php

示例4: getAction

 /**
  * Get the details of a person.
  *
  * @param int $id The ID of the person as assigned by MyAnimeList
  *
  * @return View
  */
 public function getAction($id)
 {
     // http://myanimelist.net/people/#{id}
     $downloader = $this->get('atarashii_api.communicator');
     try {
         $personDetails = $downloader->fetch('/people/' . $id);
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     } catch (Exception\ClientErrorResponseException $e) {
         $personDetails = $e->getResponse();
     }
     if (strpos($personDetails, 'This page doesn\'t exist') !== false) {
         return $this->view(array('error' => 'not-found'), 200);
     } else {
         $person = PersonParser::parse($personDetails);
         $response = new Response();
         $response->setPublic();
         $response->setMaxAge(86400);
         //One day
         $response->headers->addCacheControlDirective('must-revalidate', true);
         //Also, set "expires" header for caches that don't understand Cache-Control
         $date = new \DateTime();
         $date->modify('+172800 seconds');
         //two days
         $response->setExpires($date);
         $view = $this->view($person);
         $view->setResponse($response);
         $view->setStatusCode(200);
         return $view;
     }
 }
开发者ID:AnimeNeko,项目名称:atarashii-mal-api,代码行数:38,代码来源:PersonController.php

示例5: show

 public function show()
 {
     $assetic = $this->getServices()->get($this->getServices()->getProperty('asseticServiceName', 'assetic'));
     $response = new Response();
     $response->setExpires(new \DateTime());
     if (empty($this->asset) || strpos($this->asset, '/') === false) {
         $response->setStatusCode(400);
         return $response;
     }
     list(, $formulaName, ) = explode('/', $this->asset);
     // asset not found
     if (empty($formulaName) || !$assetic->getAssetManager()->has($formulaName)) {
         $response->setStatusCode(404);
         return $response;
     }
     $formula = $assetic->getAssetManager()->getFormula($formulaName);
     if ($formula[0] instanceof AssetInterface) {
         $asset = $formula[0];
     } else {
         $asset = $assetic->getFactory()->createAsset($formula[0], $formula[1], $formula[2]);
     }
     if (null !== ($lastModified = $asset->getLastModified())) {
         $date = new \DateTime();
         $date->setTimestamp($lastModified);
         $response->setLastModified($date);
     }
     $formula['last_modified'] = $lastModified;
     $response->setETag(md5($asset->getContent()));
     $this->defineContentType($response);
     if ($response->isNotModified($this->getContext()->getRequest())) {
         return $response;
     }
     $response->setContent($this->cacheAsset($asset)->dump());
     return $response;
 }
开发者ID:nitronet,项目名称:fwk-assetic,代码行数:35,代码来源:AssetAction.php

示例6: indexAction

 public function indexAction($search, $page = 1)
 {
     $this->construct();
     $res = new Response();
     $res->setExpires((new \DateTime())->modify('+ 120 seconds'));
     $finder = $this->container->get('fos_elastica.finder.search.post');
     if (!$search) {
         $search = $this->get('request')->query->get('search');
     }
     $res->setETag(md5($search));
     $posts = $projects = $photoCategories = $photos = array();
     $res->setPublic();
     try {
         $posts = $this->tryCache($search, 'post_search', 'ArrayCollection<Aldor\\BlogBundle\\Entity\\Post>', 'fos_elastica.finder.search.post');
         $projects = $this->tryCache($search, 'projects', 'ArrayCollection<Aldor\\PortfolioBundle\\Entity\\Project>', 'fos_elastica.finder.search.project');
         $photoCategories = $this->tryCache($search, 'photo_catgory', 'ArrayCollection<Aldor\\GalleryBundle\\Entity\\PhotoCategory>', 'fos_elastica.finder.search.photo_category');
         $photos = $this->tryCache($search, 'photos', 'ArrayCollection<Aldor\\GalleryBundle\\Entity\\Photo>', 'fos_elastica.finder.search.photo');
     } catch (\Exception $err) {
         $logger = $this->get('logger');
         $logger->error('Elastica error' . $err);
     }
     $posts = $this->m_paginator->paginate($posts, $this->get('request')->query->get('strona', $page), $this->container->getParameter('max_post_on_page'));
     $projects = $this->m_paginator->paginate($projects, $this->get('request')->query->get('strona', $page), $this->container->getParameter('max_post_on_page'));
     $posts->setUsedRoute('inftech_search');
     $posts->setParam('search', '*' . $search . '*');
     $seoPage = $this->container->get('sonata.seo.page');
     $seoPage->setTitle('Szukaj - mkaciuba.pl')->addMeta('name', 'description', 'Marcin Kaciuba - blog o tematyce IT i fotografii')->addMeta('property', 'og:title', 'Szukaj - mkaciuba.pl')->addMeta('property', 'og:type', 'blog')->addMeta('property', 'og:description', 'Marcin Kaciuba - blog o tematyce IT i fotografii');
     return $this->render('AldorInftechBundle:Search:index.html.twig', array('posts' => $posts, 'photoCategories' => $photoCategories, 'projects' => $projects, 'resultCount' => count($posts) + count($photoCategories) + count($projects) + count($photos), 'photos' => $photos, 'search' => $search), $res);
 }
开发者ID:Aldor007,项目名称:mkaciuba.pl,代码行数:29,代码来源:SearchController.php

示例7: footerAction

 /**
  * Renders the footer
  *
  * @return Response
  */
 public function footerAction()
 {
     $footerContent = $this->get('metalfrance.repository.layout')->getFooter();
     $response = new Response();
     $response->setExpires(new DateTime('next year'));
     $response->headers->set('X-Location-Id', $footerContent->contentInfo->mainLocationId);
     return $this->render('MetalFranceSiteBundle:Layout:footer.html.twig', ['footer_content' => $footerContent], $response);
 }
开发者ID:obenyoussef,项目名称:metalfrance,代码行数:13,代码来源:LayoutController.php

示例8: uncachableResponse

 public function uncachableResponse()
 {
     $response = new Response();
     $date = new DateTime();
     $date->modify('-1 day');
     $response->setExpires($date);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->headers->addCacheControlDirective('no-store', true);
     $response->headers->addCacheControlDirective('no-cache', true);
     return $response;
 }
开发者ID:hotfics,项目名称:lichess-old,代码行数:11,代码来源:Provider.php

示例9: execute

 public function execute(Request $request, Config $config, WorkingFolder $workingFolder, ResizedImageRepository $resizedImageRepository, CacheManager $cache)
 {
     $fileName = (string) $request->query->get('fileName');
     list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->get('size'));
     $downloadedFile = new DownloadedFile($fileName, $this->app);
     $downloadedFile->isValid();
     if (!Image::isSupportedExtension(pathinfo($fileName, PATHINFO_EXTENSION), $config->get('thumbnails.bmpSupported'))) {
         throw new InvalidExtensionException('Unsupported image type or not image file');
     }
     Utils::removeSessionCacheHeaders();
     $response = new Response();
     $response->setPublic();
     $response->setEtag(dechex($downloadedFile->getTimestamp()) . "-" . dechex($downloadedFile->getSize()));
     $lastModificationDate = new \DateTime();
     $lastModificationDate->setTimestamp($downloadedFile->getTimestamp());
     $response->setLastModified($lastModificationDate);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $imagePreviewCacheExpires = (int) $config->get('cache.imagePreview');
     if ($imagePreviewCacheExpires > 0) {
         $response->setMaxAge($imagePreviewCacheExpires);
         $expireTime = new \DateTime();
         $expireTime->modify('+' . $imagePreviewCacheExpires . 'seconds');
         $response->setExpires($expireTime);
     }
     $cachedInfoPath = Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName);
     $cachedInfo = $cache->get($cachedInfoPath);
     $resultImage = null;
     // Try to reuse existing resized image
     if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
         // Fix received aspect ratio
         $size = Image::calculateAspectRatio($requestedWidth, $requestedHeight, $cachedInfo['width'], $cachedInfo['height']);
         $resizedImage = $resizedImageRepository->getResizedImageBySize($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $size['width'], $size['height']);
         if ($resizedImage) {
             $resultImage = Image::create($resizedImage->getImageData());
         }
     }
     // Fallback - get and resize the original image
     if (null === $resultImage) {
         $resultImage = Image::create($downloadedFile->getContents(), $config->get('thumbnails.bmpSupported'));
         $cache->set($cachedInfoPath, $resultImage->getInfo());
         $resultImage->resize($requestedWidth, $requestedHeight);
     }
     $mimeType = $resultImage->getMimeType();
     if (in_array($mimeType, array('image/bmp', 'image/x-ms-bmp'))) {
         $mimeType = 'image/jpeg';
         // Image::getData() by default converts resized images to JPG
     }
     $response->headers->set('Content-Type', $mimeType . '; name="' . $downloadedFile->getFileName() . '"');
     $response->setContent($resultImage->getData());
     return $response;
 }
开发者ID:knodejs,项目名称:ckfinder_gulp,代码行数:53,代码来源:ImagePreview.php

示例10: displayAction

 public function displayAction($id)
 {
     $basepath = $this->container->getParameter('symfony_cmf_content.static_basepath');
     $image = $this->dm->find(null, $basepath . '/' . $id);
     $data = stream_get_contents($image->content);
     $response = new Response($data);
     $response->headers->set('Content-Type', 'image/jpeg');
     $response->setPublic();
     $date = new \DateTime();
     $date->setTimestamp(time() + 332640000);
     $response->setExpires($date);
     $response->setMaxAge(332640000);
     return $response;
 }
开发者ID:0x616469,项目名称:cmf-sandbox,代码行数:14,代码来源:ImageController.php

示例11: indexAction

 /**
  * @Route("/{code}", name="short_url")
  */
 public function indexAction(Request $request, $code)
 {
     $shortCode = $this->get('short_url')->get($code);
     if ($shortCode) {
         $response = new RedirectResponse($shortCode->getUrl(), RedirectResponse::HTTP_FOUND);
         $response->setPublic();
         $response->setExpires(new DateTime('+1 year'));
         return $response;
     }
     $response = new Response();
     $response->setPublic();
     $response->setExpires(new DateTime('+1 hour'));
     return $this->render('notFound.html.twig', ['code' => $code], $response);
 }
开发者ID:ravenhaus,项目名称:shortUrl,代码行数:17,代码来源:ShortUrlController.php

示例12: channelAction

 /**
  * public function channelAction()
  *
  * This function mimics the channel.html file suggested by facebook.
  *
  * References :
  * https://developers.facebook.com/docs/reference/javascript/
  *
  * @version         1.0
  *
  * @author          Antoine Durieux
  *
  * @return Response
  */
 public function channelAction()
 {
     // Retrieve parameters from the container.
     $culture = $this->container->getParameter('fos_facebook.culture');
     $cacheExpire = $this->container->getParameter('fos_facebook.channel.expire');
     // Compute expiration date.
     $date = new \DateTime();
     $date->modify('+' . $cacheExpire . ' seconds');
     // Generate new response, and set parameters recommended by Facebook.
     $response = new Response();
     $response->headers->set("Pragma", "public");
     $response->setMaxAge($cacheExpire);
     $response->setExpires($date);
     $response->setContent('<script src="//connect.facebook.net/' . $culture . '/all.js"></script>');
     return $response;
 }
开发者ID:hientranquang,项目名称:FOSFacebookBundle,代码行数:30,代码来源:FacebookController.php

示例13: indexAction

 /**
  * List of posts with HTTP Response
  * @return Response
  */
 public function indexAction(Request $request)
 {
     $date = new \Datetime('+1 day');
     $response = new Response();
     $response->setETag($response->getContent());
     $response->setLastModified($date);
     $response->setPublic();
     $response->setExpires($date);
     $response->headers->addCacheControlDirective('must-revalidate', true);
     if ($response->isNotModified($request)) {
         return $response;
     } else {
         $em = $this->getDoctrine()->getManager();
         $posts = $em->getRepository('HeticPublicBundle:Post')->findAll();
         return $this->render('HeticPublicBundle:Post:index.html.twig', array('posts' => $posts));
     }
 }
开发者ID:symfomany,项目名称:prez,代码行数:21,代码来源:PostController.php

示例14: _prepareResponse

 protected function _prepareResponse($etag, $modifed = null, $expires = " +300 seconds", $s_max_age = 600, $max_age = 300)
 {
     $response = new Response();
     $currentTime = new \DateTime();
     $req = $this->getRequest();
     $deviceView = $this->m_deviceView->getViewType();
     $response->setExpires($currentTime->modify($expires));
     $response->setETag(md5($etag . $deviceView . $req->headers->get('x-forwarded-proto')));
     $response->setPublic();
     $response->setMaxAge($max_age);
     $response->setSharedMaxAge($s_max_age);
     if ($modifed) {
         $response->setLastModified($modifed);
     }
     $response->setVary(array('x-device-type', 'x-forwarded-proto'));
     return $response;
 }
开发者ID:Aldor007,项目名称:mkaciuba.pl,代码行数:17,代码来源:BaseController.php

示例15: 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


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