本文整理汇总了PHP中Symfony\Component\HttpFoundation\RedirectResponse::send方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectResponse::send方法的具体用法?PHP RedirectResponse::send怎么用?PHP RedirectResponse::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\RedirectResponse
的用法示例。
在下文中一共展示了RedirectResponse::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listener
public static function listener(RequestEvent $requestEvent)
{
$request = $requestEvent->getRequest();
$pathInfo = $request->getPathInfo();
$session = $requestEvent->getSession();
$configSecurity = $requestEvent->getSecurityConfig();
$routes = $requestEvent->getRoutes();
$context = new RequestContext();
$matcher = new UrlMatcher($routes, $context);
$context->fromRequest($request);
$matching = $matcher->match($pathInfo);
$matchedRoute = $matching['_route'];
if (isset($configSecurity['protected'])) {
$protected = $configSecurity['protected'];
$protectedRoutes = $protected['routes'];
$sessionKey = $protected['session'];
$notLoggedRoute = $protected['not_logged'];
$loggedRoute = $protected['logged'];
$redirectRoute = null;
if ($session->get($sessionKey) && $matchedRoute === $notLoggedRoute) {
$redirectRoute = $routes->get($loggedRoute);
}
if (!$session->get($sessionKey) && in_array($matchedRoute, $protectedRoutes)) {
$redirectRoute = $routes->get($notLoggedRoute);
}
if ($redirectRoute) {
$redirectResponse = new RedirectResponse($request->getBaseUrl() . $redirectRoute->getPath());
$redirectResponse->send();
}
}
}
示例2: saveAction
/**
* @Route("/admin/asset/location-type/save")
* @Method("POST")
*/
public function saveAction(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN', null, 'Unable to access this page!');
$em = $this->getDoctrine()->getManager();
$response = new Response();
$locationTypes = [];
$locationTypes['types'] = $em->getRepository('AppBundle\\Entity\\Asset\\LocationType')->findAll();
$form = $this->createForm(LocationTypesType::class, $locationTypes, ['allow_extra_fields' => true]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$locationTypes = $form->getData();
foreach ($locationTypes['types'] as $type) {
$em->persist($type);
}
$em->flush();
$this->addFlash('notice', 'common.success');
$response = new RedirectResponse($this->generateUrl('app_admin_asset_locationtype_index', [], UrlGeneratorInterface::ABSOLUTE_URL));
$response->prepare($request);
return $response->send();
} else {
$errorMessages = [];
$formData = $form->all();
foreach ($formData as $name => $item) {
if (!$item->isValid()) {
$errorMessages[] = $name . ' - ' . $item->getErrors(true);
}
}
return $this->render('admin/asset/location_types.html.twig', array('location_types_form' => $form->createView(), 'base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..')));
}
}
示例3: themeAction
/**
* Переключение активной темы
* @Route("/theme/{theme}", name="theme", defaults={"theme"="web"}, requirements={"theme"="web|phone"})
*/
public function themeAction(Request $request, $theme)
{
$referer = $request->headers->get('referer');
$response = new RedirectResponse($referer);
$cookie = new Cookie('theme', $theme, 0, '/', null, false, false);
$response->headers->setCookie($cookie);
$response->send();
}
示例4: run
public function run()
{
$user = $this->getUser();
if (empty($user)) {
$response = new RedirectResponse($this->getApp()->generateUrl('home'));
$response->send();
exit;
}
}
示例5: redirect
/**
* Fast redirect in web environment
* @param string $to
* @param bool $full
*/
public function redirect($to, $full = false)
{
$to = trim($to, '/');
if (false === $full && !Str::startsWith(App::$Alias->baseUrl, $to)) {
$to = App::$Alias->baseUrl . '/' . $to;
}
$redirect = new FoundationRedirect($to);
$redirect->send();
exit('Redirecting to ' . $to . ' ...');
}
示例6: submitForm
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (isset($form)) {
if (isset($form['#token'])) {
$collection_name = Html::escape($form['searchblox_collection']['#value']);
\Drupal::state()->set('searchblox_collection', $collection_name);
$response = new RedirectResponse(\Drupal::url('searchblox.step3'));
$response->send();
return;
}
}
}
示例7: authorize
public function authorize()
{
if ($this->request->has('code')) {
$state = $this->request->get('state');
// This was a callback request from linkedin, get the token
return $this->wunderlistService->requestAccessToken($this->request->get('code'), $state);
} else {
$url = $this->wunderlistService->getAuthorizationUri();
$response = new RedirectResponse($url);
$response->send();
}
}
示例8: send
public function send()
{
$cleared = \Cookie::getClearedCookies();
foreach ($cleared as $cookie) {
$this->headers->clearCookie($cookie);
}
// First, we see if we have any cookies to send along
$cookies = \Cookie::getCookies();
foreach ($cookies as $cookie) {
$this->headers->setCookie($cookie);
}
parent::send();
}
示例9: handle
/**
* Handles an access denied failure redirecting to home page
*
* @param Request $request
* @param AccessDeniedException $accessDeniedException
*
* @return Response may return null
*/
public function handle(Request $request, AccessDeniedException $accessDeniedException)
{
$this->logger->error('User tried to access: ' . $request->getUri());
if ($request->isXmlHttpRequest()) {
return new JsonResponse(['message' => $accessDeniedException->getMessage(), 'trace' => $accessDeniedException->getTraceAsString(), 'exception' => get_class($accessDeniedException)], Response::HTTP_SERVICE_UNAVAILABLE);
} else {
$url = $request->getBasePath() !== "" ? $request->getBasePath() : "/";
$response = new RedirectResponse($url);
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->prepare($request);
return $response->send();
}
}
示例10: exec
public static function exec($url, $status = 302, $cookies = array())
{
trigger_error('deprecated since version 2.1 and will be removed in 2.3. A response can not be send before the end of the script. Please use RedirectResponse directly', E_USER_DEPRECATED);
if (false == Tlog::getInstance()->showRedirect($url)) {
$response = new RedirectResponse($url, $status);
foreach ($cookies as $cookie) {
if (!$cookie instanceof Cookie) {
throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
}
$response->headers->setCookie($cookie);
}
$response->send();
}
}
示例11: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
//var_dump(get_class($controller[0]));
//exit;
if (!$controller[0] instanceof SecurityController) {
$needRegister = $event->getRequest()->getSession()->get('needRegister');
if ($needRegister === true) {
$url = $this->router->generate('register');
$redirect = new RedirectResponse($url);
$redirect->send();
}
}
}
示例12: submitForm
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (isset($form)) {
if (isset($form['#token'])) {
$api = Html::escape($form['searchblox_api']['#value']);
$location = rtrim(Html::escape($form['searchblox_location']['#value']), '/');
$location = searchblox_addhttp($location);
$port_no = intval(Html::escape($form['searchblox_portno']['#value']));
\Drupal::state()->set('searchblox_apikey', $api);
\Drupal::state()->set('searchblox_location', $location);
\Drupal::state()->set('searchblox_portno', $port_no);
$response = new RedirectResponse(\Drupal::url('searchblox.step2'));
$response->send();
return;
}
}
}
示例13: zen_redirect
/**
* Redirect to a url (safely)
*
* This function safely shuts down Symfony by making sure the
* response and terminate kernel events are called.
*
* @param string $url The url to redirect to
* @param int $response_code http response code (defaults to 302)
*/
function zen_redirect($url, $responseCode = 302)
{
// fix accidental ampersands
$url = str_replace(array('&', '&&'), '&', $url);
$container = Runtime::getContainer();
$request = $container->get('request');
if (ENABLE_SSL == 'true' && $request->isSecure()) {
$url = str_replace('http://', 'https://', $url);
}
$response = new RedirectResponse($url, $responseCode);
$httpKernel = $container->get('http_kernel');
$event = new FilterResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher = $container->get('event_dispatcher');
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$response->send();
$httpKernel->terminate($request, $response);
exit;
}
示例14: submitForm
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (isset($form)) {
if (isset($form['#token'])) {
$collection_name = Html::escape($form['searchblox_collection']['#value']);
$resp = searchblox_check_collection($collection_name);
// check weather collection name is valid
if ($resp !== true) {
$form_state->setErrorByName($resp);
}
if ($resp) {
\Drupal::state()->set('searchblox_collection', $collection_name);
$response = new RedirectResponse(\Drupal::url('searchblox.step3'));
$response->send();
return;
}
}
}
}
示例15: authorize
public function authorize()
{
$request = $this->getRequest();
$session = $request->getSession();
if (!$request->query->has('code')) {
// If we don't have an authorization code then get one
$authUrl = $this->provider->getAuthorizationUrl();
$session->set('oauth2state', $this->provider->state);
$response = new RedirectResponse($authUrl);
$response->send();
} elseif (empty($request->query->get('state')) || $request->query->get('state') !== $session->get('oauth2state')) {
$session->remove('oauth2state');
throw new \InvalidArgumentException('Invalid State');
} else {
// Try to get an access token (using the authorization code grant)
$this->token = $this->provider->getAccessToken('authorization_code', ['code' => $this->request->query->get('code')]);
}
return $this->token->accessToken;
}