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


PHP Response::setETag方法代码示例

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


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

示例1: indexAction

 public function indexAction()
 {
     $response = new Response();
     $response->setPublic();
     if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $response->setETag(md5((string) $this->getUser()->getType()));
         switch ($this->getUser()->getType()) {
             case 'publisher':
                 $homepage = 'Publisher';
                 break;
             case 'advertiser':
                 $homepage = 'Advertiser';
                 break;
         }
         $response->setMaxAge(60 * 30);
     } else {
         $response->setETag(md5('public'));
         $homepage = 'Public';
         $response->setMaxAge(60 * 60 * 10);
     }
     $response->headers->set('Vary', 'Cookie');
     // $response->headers->addCacheControlDirective('must-revalidate', true);
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     }
     return $this->render('VifeedFrontendBundle:' . $homepage . ':homepage.html.twig', [], $response);
 }
开发者ID:bzis,项目名称:zomba,代码行数:27,代码来源:DefaultController.php

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

示例3: getResponse

 private function getResponse(Request $request, $name, array $files, $content_type)
 {
     if (!isset($files[$name])) {
         return new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
     }
     $file = $files[$name];
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge(self::EXPIRED_TIME);
     $response->setSharedMaxAge(self::EXPIRED_TIME);
     $response->headers->set('Content-Type', $content_type);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $date = new \DateTime();
     $date->setTimestamp(strtotime($this->container->getParameter('sf.version')));
     $response->setETag($date->getTimestamp());
     $response->setLastModified($date);
     if ($response->isNotModified($request)) {
         return $response;
     }
     if (!file_exists($file)) {
         throw new \Exception(sprintf("file `%s`, `%s` not exists", $name, $file));
     }
     $response->setContent(file_get_contents($file));
     return $response;
 }
开发者ID:symforce,项目名称:symforce-admin,代码行数:26,代码来源:IeController.php

示例4: onKernelController

 /**
  * Handles HTTP validation headers.
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     if (!($configuration = $request->attributes->get('_cache'))) {
         return;
     }
     $response = new Response();
     $lastModifiedDate = '';
     if ($configuration->getLastModified()) {
         $lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
         $response->setLastModified($lastModifiedDate);
     }
     $etag = '';
     if ($configuration->getETag()) {
         $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
         $response->setETag($etag);
     }
     if ($response->isNotModified($request)) {
         $event->setController(function () use($response) {
             return $response;
         });
     } else {
         if ($etag) {
             $this->etags[$request] = $etag;
         }
         if ($lastModifiedDate) {
             $this->lastModifiedDates[$request] = $lastModifiedDate;
         }
     }
 }
开发者ID:raphydev,项目名称:onep,代码行数:33,代码来源:HttpCacheListener.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: getETag

 public function getETag(Request $request, $res, $_format = 'json')
 {
     $response = new Response($res);
     $response->setETag(md5($response->getContent()));
     $response->setPublic();
     // make sure the response is public/cacheable
     $response->headers->set('Content-Type', $this->getContentType($_format));
     $response->isNotModified($request);
     return $response;
 }
开发者ID:jocoonopa,项目名称:avenue,代码行数:10,代码来源:ResponseHandler.php

示例7: userInfoAction

 /**
  * This Action displays the user info (name and profile pic)
  *
  * @return Response
  */
 public function userInfoAction()
 {
     $tokenHandler = $this->get('instaphp_token_handler');
     $response = new Response();
     $response->setETag($tokenHandler->getToken());
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     } else {
         $instaphp = $this->get('instaphp');
         $info = $instaphp->Users->Info('self');
         return $this->render('OhInstagramBundle:Instagram:userInfo.html.twig', array('info' => $info), $response);
     }
 }
开发者ID:rmasters,项目名称:InstagramBundle,代码行数:18,代码来源:InstagramController.php

示例8: helloWorldTwigCachedAction

 public function helloWorldTwigCachedAction()
 {
     $response = new Response();
     $response->setPublic();
     $response->setETag("HelloWorldTwigTag");
     //        $response->setLastModified( new DateTime( "2012-01-01 00:00:00+0000" ) );
     // Check that the Response is not modified for the given Request
     if ($response->isNotModified($this->getRequest())) {
         // return the 304 Response immediately
         return $response;
     }
     return $this->render("eZDemoBundle::hello_world.html.twig", array(), $response);
 }
开发者ID:nlescure,项目名称:ezpublish5,代码行数:13,代码来源:DemoController.php

示例9: listAction

 public function listAction(Request $request, Application $app)
 {
     $pager = $app['document_repository']->paginate((int) $request->query->get('page', 1), (int) $request->query->get('limit', 10));
     $response = new Response();
     $results = (array) $pager->getCurrentPageResults();
     $response->setPublic();
     $response->setETag($this->computeETag($request, $results));
     if ($response->isNotModified($request)) {
         return $response;
     }
     $documents = $app['hateoas.pagerfanta_factory']->createRepresentation($pager, new Route('document_list', [], true), new CollectionRepresentation($results, 'documents', null, null, null, [new Relation("expr(curies_prefix ~ ':documents')", new Route("document_list", [], true))]), true);
     return $app['view_handler']->handle($documents, 200, [], $response);
 }
开发者ID:slavcodev,项目名称:Propilex,代码行数:13,代码来源:DocumentController.php

示例10: checkEtagsAndStuff

 private function checkEtagsAndStuff(Request $request)
 {
     $hash = $this->getGitLatestCommitHash();
     if (!empty($hash)) {
         $response = new Response();
         $response->setMaxAge(600);
         $response->setPublic();
         $response->setETag(md5($hash));
         if ($response->isNotModified($request)) {
             return $response;
         }
     }
     return null;
 }
开发者ID:broadr,项目名称:server,代码行数:14,代码来源:RequestListener.php

示例11: _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

示例12: indexAction

 public function indexAction($enabledSlides)
 {
     $response = new Response();
     $response->setPublic();
     $response->setSharedMaxAge(100800);
     $response->setETag(md5('public'));
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     }
     $slides = ['main' => ['type' => 'advertiser', 'title' => 'Как это работает', 'text' => 'Zombakka — это простая и быстрая платформа<br>для продвижения ваших видео.', 'btnTitle' => 'Узнать больше'], 'music' => ['type' => 'advertiser', 'title' => 'Для музыкантов', 'text' => 'Сервис продвижения видео<br> для независимых исполнителей.', 'btnUrl' => $this->generateUrl('for_musicians'), 'btnTitle' => 'Запустить кампанию'], 'partners' => ['type' => 'advertiser', 'title' => 'Для партнеров', 'text' => 'Специальные условия для<br> рекламных агентств и партнеров.', 'btnUrl' => $this->generateUrl('for_partners'), 'btnTitle' => 'Узнать больше'], 'movies' => ['type' => 'advertiser', 'title' => 'Для фильмов', 'text' => 'Сервис для продвижения фильмов от киностудий<br> или независимых режиссеров.', 'btnUrl' => $this->generateUrl('for_movies'), 'btnTitle' => 'Запустить кампанию'], 'games' => ['type' => 'advertiser', 'title' => 'Для игр', 'text' => 'Сервис для продвижения игр от ведущих<br> издателей или инди разработчиков.', 'btnUrl' => $this->generateUrl('for_games'), 'btnTitle' => 'Запустить кампанию'], 'companies' => ['type' => 'advertiser', 'title' => 'Для компаний', 'text' => 'Сервис для продвижения брендов<br> вирусными технологиями.', 'btnUrl' => $this->generateUrl('for_companies'), 'btnTitle' => 'Запустить кампанию'], 'publishers' => ['type' => 'publisher', 'title' => 'Для владельцев площадок', 'text' => 'Сервис для безграничного заработка<br> на просмотрах видео, размещенных на ваших площадках.', 'btnUrl' => $this->generateUrl('for_publishers'), 'btnTitle' => 'Начать зарабатывать']];
     foreach ($slides as $key => $slide) {
         if (!in_array($key, $enabledSlides)) {
             unset($slides[$key]);
         }
     }
     return $this->render('VifeedFrontendBundle:Public:carousel.html.twig', ['slides' => $slides], $response);
 }
开发者ID:bzis,项目名称:zomba,代码行数:17,代码来源:CarouselController.php

示例13: indexAction

 public function indexAction($enabledVideos)
 {
     $response = new Response();
     $response->setPublic();
     $response->setSharedMaxAge(100800);
     $response->setETag(md5('public'));
     if ($response->isNotModified($this->getRequest())) {
         return $response;
     }
     $videos = ['films' => ['title' => 'Brick Mansions Promo', 'before' => '320 700', 'after' => '743 168'], 'films2' => ['title' => 'Несносный дед. Русский трейлер', 'before' => '215 521', 'after' => '629 878'], 'for_company1' => ['title' => 'Как остановить время', 'before' => '850 932', 'after' => '1 475 031'], 'for_company2' => ['title' => 'Шашлычок 72 или как защитить ваш офис', 'before' => '397 000', 'after' => '813 935'], 'game1' => ['title' => 'Вечеринка компании Wargaming', 'before' => '12 834', 'after' => '122 839'], 'game2' => ['title' => 'Pro Игры - Metro: Last Light', 'before' => '154 000', 'after' => '487 392'], 'music2' => ['title' => 'NuSkOOl — Lambretta', 'before' => '1 629', 'after' => '39 991'], 'music1' => ['title' => 'LITTLE BIG - Everyday I\'m drinking', 'before' => '1 789 013', 'after' => '3 610 259']];
     foreach ($videos as $key => $video) {
         if (!in_array($key, $enabledVideos)) {
             unset($videos[$key]);
         }
     }
     return $this->render('VifeedFrontendBundle:Public:videos.html.twig', ['videos' => $videos], $response);
 }
开发者ID:bzis,项目名称:zomba,代码行数:17,代码来源:VideosController.php

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

示例15: indexAction

 /**
  * Generates a JavaScript file with client-side localization constants.
  *
  * @param Request $request Incoming request.
  * @return Response Prepared JavaScript file with client side localization
  * constants.
  */
 public function indexAction(Request $request)
 {
     $locale = $request->attributes->get('locale');
     $item = $this->getCache()->getItem('translation/js/' . $locale);
     $content = $item->get(Invalidation::OLD);
     if ($item->isMiss()) {
         $item->lock();
         $messages = load_messages($locale);
         // Store JSON-encoded data to reduce count of json_encode calls.
         $content = sprintf('%s(%s);', 'Mibew.Localization.set', json_encode($messages));
         $item->set($content);
     }
     // Session is started automatically during application initialization
     // and PHP sets "Cache-Control" and "Expires" headers to forbid caching
     // and to keep the session private. In this script we actually does not
     // use session stuff, thus we can remove these headers to provide
     // caching. Notice that all headers are removed to clear "Set-Cookie"
     // header with session ID and may be some other unsafe headers that
     // must not be cached.
     header_remove();
     // The whole response body (JSON-encoded with a callback function) is
     // cached via cache backend, thus it's simpler to use Symfony's
     // Response class instead of JsonResponse.
     $response = new Response();
     $response->headers->set('Content-Type', 'text/javascript');
     // Set various cache headers
     $response->setPublic();
     $response->setMaxAge(120);
     if ($item->getCreation()) {
         // Creation field can be unavailable for some cache drivers.
         $response->setLastModified($item->getCreation());
     }
     $response->setETag(sha1($content));
     if ($response->isNotModified($request)) {
         $response->setNotModified();
         // We does not need to send content for the client. Just return 304
         // status code.
         return $response;
     }
     // Pass the whole response for the client.
     $response->setContent($content);
     return $response;
 }
开发者ID:aburakovskiy,项目名称:mibew,代码行数:50,代码来源:JsTranslationController.php


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