本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setRedirect方法的具体用法?PHP Response::setRedirect怎么用?PHP Response::setRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::setRedirect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
/**
* {@inheritdoc}
*/
public function start(Request $request, AuthenticationException $authException = null)
{
if ($this->useForward) {
return $event->getSubject()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);
}
$response = new Response();
$response->setRedirect(0 !== strpos($this->loginPath, 'http') ? $request->getUriForPath($this->loginPath) : $this->loginPath, 302);
return $response;
}
示例2: handle
/**
*
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if ($this->logoutPath !== $request->getPathInfo()) {
return;
}
$this->securityContext->setToken(null);
$request->getSession()->invalidate();
$response = new Response();
$response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
$event->setReturnValue($response);
return true;
}
示例3: handle
/**
* Performs the logout if requested
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->get('request');
if ($this->logoutPath !== $request->getPathInfo()) {
return;
}
$response = new Response();
$response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
$token = $this->securityContext->getToken();
foreach ($this->handlers as $handler) {
$handler->logout($request, $response, $token);
}
$this->securityContext->setToken(null);
$event->setReturnValue($response);
return true;
}
示例4: handle
/**
* Performs the logout if requested
*
* @param EventInterface $event An EventInterface instance
*/
public function handle(EventInterface $event)
{
$request = $event->get('request');
if ($this->logoutPath !== $request->getPathInfo()) {
return;
}
$response = new Response();
$response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
// handle multiple logout attempts gracefully
if ($token = $this->securityContext->getToken()) {
foreach ($this->handlers as $handler) {
$handler->logout($request, $response, $token);
}
}
$this->securityContext->setToken(null);
$event->setProcessed();
return $response;
}
示例5: start
public function start(Request $request, AuthenticationException $authException = null)
{
$scheme = $request->isSecure() ? 'http' : 'https';
if ('http' === $scheme && 80 != $this->httpPort) {
$port = ':' . $this->httpPort;
} elseif ('https' === $scheme && 443 != $this->httpPort) {
$port = ':' . $this->httpsPort;
} else {
$port = '';
}
$qs = $request->getQueryString();
if (null !== $qs) {
$qs = '?' . $qs;
}
$url = $scheme . '://' . $request->getHost() . $port . $request->getScriptName() . $request->getPathInfo() . $qs;
$response = new Response();
$response->setRedirect($url, 301);
return $response;
}
示例6: onSuccess
protected function onSuccess(Request $request, TokenInterface $token)
{
if (null !== $this->logger) {
$this->logger->debug('User has been authenticated successfully');
}
$this->securityContext->setToken($token);
$session = $request->getSession();
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::LAST_USERNAME);
$response = new Response();
$path = $this->determineTargetUrl($request);
$response->setRedirect(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
return $response;
}
示例7: handle
/**
* Handles digest authentication.
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if (!$request->get($this->usernameParameter)) {
return;
}
if ('_exit' === $request->get($this->usernameParameter)) {
$this->securityContext->setToken($this->attemptExitUser($request));
} else {
try {
$this->securityContext->setToken($this->attemptSwitchUser($request));
} catch (AuthenticationException $e) {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Switch User failed: "%s"', $e->getMessage()));
}
}
}
$response = new Response();
$request->server->set('QUERY_STRING', '');
$response->setRedirect($request->getUri(), 302);
$event->setReturnValue($response);
return true;
}
示例8: onSuccess
protected function onSuccess(EventInterface $event, Request $request, TokenInterface $token)
{
if (null !== $this->logger) {
$this->logger->debug('User has been authenticated successfully');
}
$this->securityContext->setToken($token);
$session = $request->getSession();
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::LAST_USERNAME);
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token)));
}
if (null !== $this->successHandler) {
$response = $this->successHandler->onAuthenticationSuccess($request, $token);
} else {
$response = new Response();
$path = $this->determineTargetUrl($request);
$response->setRedirect(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
}
if (null !== $this->rememberMeServices) {
$this->rememberMeServices->loginSuccess($request, $response, $token);
}
return $response;
}