本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setVary方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setVary方法的具体用法?PHP Response::setVary怎么用?PHP Response::setVary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::setVary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction(Request $request)
{
//mini formulaire d'abonnement
$news = new Newsletter();
$form = $this->createFormBuilder($news)->add('news', 'email')->add('Envoyer', 'submit')->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$email = $news->getNews();
$message = \Swift_Message::newInstance()->setSubject('Bonjour')->setFrom($email)->setTo('stefchrys@yahoo.fr')->setBody('Bonjour Fabrice cet email : ' . $email . ' souhaite un abonnement à votre newsletter, cordialement');
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('front_homepage'));
}
$essais = $this->getCat('essais');
$arr = $this->get('front.base.service')->recupInfo();
$arr['essais'] = $essais;
$arr['nav_accueil'] = ' ';
$arr['nav_xix'] = ' ';
$arr['nav_essais'] = 'active';
$arr['nav_litt'] = ' ';
$arr['nav_audio'] = ' ';
$arr['nav_video'] = ' ';
$arr['nav_info'] = ' ';
$arr['newsletter'] = $form->createView();
$response = new Response();
if ($this->getRequest()->isMethod('GET')) {
$response->setPublic();
$response->setSharedMaxAge(1);
$response->setVary(array('Accept-Encoding', 'User-Agent'));
}
return $this->render('FrontBundle:Essais:index.html.twig', $arr, $response);
}
示例2: listBlogPostsAction
/**
* Displays the list of blog_post
* Note: This is a fully customized controller action, it will generate the response and call
* the view. Since it is not calling the ViewControler we don't need to match a specific
* method signature.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location containing blog posts
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listBlogPostsAction(Location $location, Request $request)
{
$response = new Response();
// Setting default cache configuration (you can override it in you siteaccess config)
$response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl'));
// Make the response location cache aware for the reverse proxy
$response->headers->set('X-Location-Id', $location->id);
$response->setVary('X-User-Hash');
$viewParameters = $request->attributes->get('viewParameters');
// Getting location and content from ezpublish dedicated services
$repository = $this->getRepository();
if ($location->invisible) {
throw new NotFoundHttpException("Location #{$location->id} cannot be displayed as it is flagged as invisible.");
}
$content = $repository->getContentService()->loadContentByContentInfo($location->getContentInfo());
// Getting language for the current siteaccess
$languages = $this->getConfigResolver()->getParameter('languages');
// Using the criteria helper (a demobundle custom service) to generate our query's criteria.
// This is a good practice in order to have less code in your controller.
$criteria = $this->get('ezdemo.criteria_helper')->generateListBlogPostCriterion($location, $viewParameters, $languages);
// Generating query
$query = new Query();
$query->query = $criteria;
$query->sortClauses = array(new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]));
// Initialize pagination.
$pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService()));
$pager->setMaxPerPage($this->container->getParameter('ezdemo.blog.blog_post_list.limit'));
$pager->setCurrentPage($request->get('page', 1));
return $this->render('eZDemoBundle:full:blog.html.twig', array('location' => $location, 'content' => $content, 'pagerBlog' => $pager), $response);
}
示例3: userLinksAction
/**
* Renders page header links with cache control
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function userLinksAction()
{
$response = new Response();
$response->setSharedMaxAge(3600);
$response->setVary('Cookie');
return $this->render("BCPageLayoutOverrideTestBundle::page_header_links.html.twig", array(), $response);
}
开发者ID:brookinsconsulting,项目名称:bcpagelayoutoverridetestbundle,代码行数:12,代码来源:BCPageLayoutOverrideTestController.php
示例4: topMenuAction
/**
* Controller for top menu
* @param int $currentLocationId
*
* @return Response
*/
public function topMenuAction($currentLocationId)
{
$rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id');
$response = new Response();
$parameters = array();
$helper = $this->get('bananamanu_simple_design.subelement_helper');
$menu = $helper->getSubElementLocation($rootLocationId);
// Get current master
try {
$currentLocation = $this->getRepository()->getLocationService()->loadLocation($currentLocationId);
$pathString = explode('/', $currentLocation->pathString);
if ((int) $pathString[3] > 0) {
$currentMasterLocationId = $pathString[3];
} else {
$currentMasterLocationId = $rootLocationId;
}
} catch (\Exception $e) {
$currentMasterLocationId = $rootLocationId;
}
// Get current user
$user = $this->getRepository()->getCurrentUser();
// Cache control
$response->setSharedMaxAge(84600);
$response->setVary('X-User-Hash');
$response->setPublic();
$parameters['menu'] = $menu;
$parameters['user'] = $user;
$parameters['currentMasterLocationId'] = $currentMasterLocationId;
return $this->render('BananamanuSimpleDesignBundle::page_topmenu.html.twig', $parameters, $response);
}
示例5: userLinksAction
/**
* Renders page header links with cache control.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function userLinksAction()
{
$response = new Response();
$response->setSharedMaxAge(3600);
$response->setVary('Cookie');
return $this->render('eZDemoBundle::page_header_links.html.twig', array(), $response);
}
示例6: viewUserInfoAction
/**
* Renders aside content regarding current user
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function viewUserInfoAction()
{
$user = $this->getRepository()->getCurrentUser();
$response = new Response();
$response->setVary('X-User-Hash');
$response->setSharedMaxAge(300);
$response->setPublic();
$params = array();
$params['time'] = time();
$params['user'] = $user;
return $this->render('BananamanuCacheDemoBundle:aside:user_info.html.twig', $params, $response);
}
示例7: showPageAction
public function showPageAction($id, $extraParams = null, $currentpage = null, $totalpageitems = null, $linkUrlParams = null)
{
// Get data to display
$page = $this->getDoctrine()->getRepository('BlogBundle:Blog')->find($id);
$userRole = $this->get('sonata_user.services.helpers')->getLoggedUserHighestRole();
$settings = $this->get('bardiscms_settings.load_settings')->loadSettings();
// Simple ACL for publishing
if ($page->getPublishState() == 0) {
return $this->render404Page();
}
if ($page->getPublishState() == 2 && $userRole == '') {
return $this->render404Page();
}
if ($userRole == "") {
$publishStates = array(1);
} else {
$publishStates = array(1, 2);
}
if ($this->container->getParameter('kernel.environment') == 'prod' && $settings->getActivateHttpCache()) {
$response = new Response();
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
// set multiple vary headers
$response->setVary(array('Accept-Encoding', 'User-Agent'));
// create a Response with a Last-Modified header
$response->setLastModified($page->getDateLastModified());
// Set response as public. Otherwise it will be private by default.
$response->setPublic();
//var_dump($response->isNotModified($this->getRequest()));
//var_dump($response->getStatusCode());
if (!$response->isNotModified($this->getRequest())) {
// Marks the Response stale
$response->expire();
} else {
// return the 304 Response immediately
$response->setSharedMaxAge(3600);
return $response;
}
}
// Set the website settings and metatags
$page = $this->get('bardiscms_settings.set_page_settings')->setPageSettings($page);
// Set the pagination variables
if (!$totalpageitems) {
if (is_object($settings)) {
$totalpageitems = $settings->getBlogItemsPerPage();
} else {
$totalpageitems = 10;
}
}
// Render the correct view depending on pagetype
return $this->renderPage($page, $id, $publishStates, $extraParams, $currentpage, $totalpageitems, $linkUrlParams);
}
示例8: testFilledBoth
public function testFilledBoth()
{
$listener = $this->getInstance(['1', '3', '4']);
$response = new Response();
$response->setVary(['1', '2']);
$event = $this->getEvent($response);
$listener->onKernelResponse($event);
$this->assertContains('1', $response->getVary());
$this->assertContains('2', $response->getVary());
$this->assertContains('3', $response->getVary());
$this->assertContains('4', $response->getVary());
$this->assertCount(4, $response->getVary());
}
示例9: setStaticPageResponseHeaders
protected function setStaticPageResponseHeaders(Response $response, array $options = array())
{
//1 week
//$seconds = 604800;
// set to 1 week or even longer once we know that the content for our
// static pages (about-us, terms-of-use, privacy-policy) have been finalized
$seconds = 600;
$response->setPublic();
$response->setMaxAge($seconds);
$response->setSharedMaxAge($seconds);
$response->setVary(array('Accept-Encoding'));
return $response;
}
示例10: _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;
}
示例11: apply
/**
* @param Response $response
*/
public function apply(Response $response)
{
if (empty($this->parameters['enabled'])) {
return;
}
$this->parameters['public'] ? $response->setPublic() : $response->setPrivate();
if (is_integer($this->parameters['maxage'])) {
$response->setMaxAge($this->parameters['maxage']);
}
if (is_integer($this->parameters['smaxage'])) {
$response->setSharedMaxAge($this->parameters['smaxage']);
}
if ($this->parameters['expires'] !== null) {
$response->setExpires(new \DateTime($this->parameters['expires']));
}
if (!empty($this->parameters['vary'])) {
$response->setVary($this->parameters['vary']);
}
}
示例12: latestContentAction
/**
* Return latest content for footer.
*
* @param $currentContentId
*
* @return Response
*/
public function latestContentAction($currentContentId)
{
$locationService = $this->getRepository()->getLocationService();
$contentService = $this->getRepository()->getContentService();
// Get the root location through ConfigResolver.
$rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id');
$rootLocation = $locationService->loadLocation($rootLocationId);
$response = new Response();
$response->setPublic();
$response->setSharedMaxAge(86400);
$response->headers->set('X-Location-Id', $rootLocationId);
$response->setVary('X-User-Hash');
// Build our exclude criterion.
// We just want to exclude locations for current content which are under root location.
$excludeLocations = $locationService->loadLocations($contentService->loadContentInfo($currentContentId), $rootLocation);
$excludeCriterion = $this->get('ezdemo.criteria_helper')->generateLocationIdExcludeCriterion($excludeLocations);
// Retrieve latest content through the MenuHelper.
// We only want articles that are located somewhere in the tree under root location.
$latestContent = $this->get('ezdemo.menu_helper')->getLatestContent($rootLocation, $this->container->getParameter('ezdemo.footer.latest_content.content_types'), $excludeCriterion, $this->container->getParameter('ezdemo.footer.latest_content.limit'));
return $this->render('eZDemoBundle:footer:latest_content.html.twig', array('latestContent' => $latestContent), $response);
}
示例13: onKernelRequest
/**
* Return the response to the context hash request with a header containing
* the generated hash.
*
* If the ttl is bigger than 0, cache headers will be set for this response.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
return;
}
if (!$this->requestMatcher->matches($event->getRequest())) {
return;
}
$hash = $this->hashGenerator->generateHash();
// status needs to be 200 as otherwise varnish will not cache the response.
$response = new Response('', 200, array($this->hashHeader => $hash, 'Content-Type' => 'application/vnd.fos.user-context-hash'));
if ($this->ttl > 0) {
$response->setClientTtl($this->ttl);
$response->setVary($this->userIdentifierHeaders);
$response->setPublic();
} else {
$response->setClientTtl(0);
$response->headers->addCacheControlDirective('no-cache');
}
$event->setResponse($response);
}
示例14: showFolderListAction
/**
* Displays the list of article.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location of a folder
* @param \Symfony\Component\HttpFoundation\Request $request request object
* @throws NotFoundHttpException $location is flagged as invisible
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showFolderListAction(Request $request, Location $location)
{
$response = new Response();
if ($location->invisible) {
throw new NotFoundHttpException("Location #{$location->id} cannot be displayed as it is flagged as invisible.");
}
$response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl'));
$response->headers->set('X-Location-Id', $location->id);
$response->setVary('X-User-Hash');
$content = $this->getRepository()->getContentService()->loadContentByContentInfo($location->getContentInfo());
// Getting language for the current siteaccess
$languages = $this->getConfigResolver()->getParameter('languages');
$excludedContentTypes = $this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types');
// Using the criteria helper (a demobundle custom service) to generate our query's criteria.
// This is a good practice in order to have less code in your controller.
$criteria = $this->get('ezdemo.criteria_helper')->generateListFolderCriterion($location, $excludedContentTypes, $languages);
// Generating query
$query = new LocationQuery();
$query->query = $criteria;
$query->sortClauses = array(new SortClause\DatePublished());
// Initialize pagination.
$pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService()));
$pager->setMaxPerPage($this->container->getParameter('ezdemo.folder.folder_list.limit'));
$pager->setCurrentPage($request->get('page', 1));
$includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types');
// Get sub folder structure
$subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion($location, $includedContentTypeIdentifiers, $languages);
$subContentQuery = new LocationQuery();
$subContentQuery->query = $subContentCriteria;
$subContentQuery->sortClauses = array(new SortClause\ContentName());
$searchService = $this->getRepository()->getSearchService();
$subContent = $searchService->findLocations($subContentQuery);
$treeItems = array();
foreach ($subContent->searchHits as $hit) {
$treeItems[] = $hit->valueObject;
}
return $this->get('ez_content')->viewLocation($location->id, 'full', true, ['pagerFolder' => $pager, 'treeItems' => $treeItems]);
}
示例15: renderTag
/**
* Renders the tag.
*
* @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderTag(Tag $tag, Request $request)
{
$configResolver = $this->getConfigResolver();
$pager = new Pagerfanta(new RelatedContentAdapter($tag, $this->tagsService));
$pager->setMaxPerPage($configResolver->getParameter('tag_view.related_content_list.limit', 'eztags'));
$pager->setCurrentPage($request->get('page', 1));
$response = new Response();
$response->headers->set('X-Tag-Id', $tag->id);
if ($configResolver->getParameter('tag_view.cache', 'eztags') === true) {
$response->setPublic();
if ($configResolver->getParameter('tag_view.ttl_cache', 'eztags') === true) {
$response->setSharedMaxAge($configResolver->getParameter('tag_view.default_ttl', 'eztags'));
}
// Make the response vary against X-User-Hash header ensures that an HTTP
// reverse proxy caches the different possible variations of the
// response as it can depend on user role for instance.
if ($request->headers->has('X-User-Hash')) {
$response->setVary('X-User-Hash');
}
$response->setLastModified($tag->modificationDate);
}
return $this->render($configResolver->getParameter('tag_view.template', 'eztags'), array('tag' => $tag, 'pager' => $pager), $response);
}