本文整理汇总了PHP中Symfony\Component\HttpFoundation\RedirectResponse::setVary方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectResponse::setVary方法的具体用法?PHP RedirectResponse::setVary怎么用?PHP RedirectResponse::setVary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\RedirectResponse
的用法示例。
在下文中一共展示了RedirectResponse::setVary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: redirectRouteAction
/**
* Returns a 301/302 redirect response based on content parameters.
*
* @param \Raindrop\RoutingBundle\Routing\Base\ExternalRouteInterface $content
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function redirectRouteAction($content)
{
$routeParams = $this->get('request')->query->all();
// do not lose eventual get parameters
if ($content instanceof ExternalRouteInterface) {
/**
* External redirect
*/
$http_status = $content->getPermanent() ? 301 : 302;
$uri = $content->getUri();
if (count($routeParams)) {
$uri .= (strpos($uri, '?') === false ? '?' : '&') . http_build_query($routeParams);
}
} else {
/**
* Inner redirect
*/
$current_route = $this->get('router')->getRouteCollection()->get($this->getRequest()->get('_route'));
$http_status = $current_route->getPermanent() ? 301 : 302;
$uri = $this->get('router')->generate($content->getName(), $routeParams, true);
}
$response = new RedirectResponse($uri, $http_status);
$response->setVary('accept-language');
return $response;
}
示例2: defaultLanguageAction
/**
* action for / to redirect to the best language based on the request language order
*/
public function defaultLanguageAction(Request $request)
{
$defaultPreferredLangs = $this->chooser->getPreferredLanguages($request->getLocale());
$bestLang = $request->getPreferredLanguage($defaultPreferredLangs);
// we only care about the first 2 characters, even if the user's preference is de_CH.
$bestLang = substr($bestLang, 0, 2);
/* Note: I wanted to send a 300 "Multiple Choices" header along with a
* Location header, but user agents may behave inconsistently in
* repsonse to this.
*
* For example Chrome was not redirecting unless the headers were
* carefully tailored for it. (In particular, it doesn't like the
* lowercase 'location' header that results from calling
* $response->headers->set('Location', '...')
*/
$url = $this->router->generate($this->routename, array('_locale' => $bestLang, '/'), true);
$response = new RedirectResponse($url, 301);
$response->setVary('accept-language');
return $response;
}
示例3: defaultLanguageAction
/**
* action for / to redirect to the best language based on the request language order
*/
public function defaultLanguageAction(Request $request, $contentDocument)
{
if (!$contentDocument instanceof RouteAwareInterface) {
throw new \Exception('The route passed to the language selection action must emulate content to have the correct route generated.');
}
// TODO: use lunetics/LocaleBundle https://github.com/symfony-cmf/cmf-sandbox/issues/54
$defaultPreferredLangs = $this->chooser->getDefaultLocalesOrder();
$bestLang = $request->getPreferredLanguage($defaultPreferredLangs);
// we only care about the first 2 characters, even if the user's preference is de_CH.
$bestLang = substr($bestLang, 0, 2);
/*
* Let the router generate the route for the requested language. The
* route provides its children, which should be the urls for each locale
* as content.
*/
$routeParams = $request->query->all();
// do not lose eventual get parameters
$routeParams['_locale'] = $bestLang;
// and set the locale
$routeParams['content'] = $contentDocument;
// and the content for the router
$url = $this->router->generate('', $routeParams, true);
/* Note: I wanted to send a 300 "Multiple Choices" header along with a
* Location header, but user agents may behave inconsistently in
* response to this.
*
* For example Chrome was not redirecting unless the headers were
* carefully tailored for it. (In particular, it doesn't like the
* lowercase 'location' header that results from calling
* $response->headers->set('Location', '...')
*/
$response = new RedirectResponse($url, 301);
$response->setVary('accept-language');
return $response;
}