當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RedirectResponse::send方法代碼示例

本文整理匯總了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();
         }
     }
 }
開發者ID:zyncro,項目名稱:framework,代碼行數:31,代碼來源:Security.php

示例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') . '/..')));
     }
 }
開發者ID:bgamrat,項目名稱:crispy-octo-parakeet,代碼行數:34,代碼來源:LocationTypeController.php

示例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();
 }
開發者ID:Quiss,項目名稱:Evrika,代碼行數:12,代碼來源:ThemeController.php

示例4: run

 public function run()
 {
     $user = $this->getUser();
     if (empty($user)) {
         $response = new RedirectResponse($this->getApp()->generateUrl('home'));
         $response->send();
         exit;
     }
 }
開發者ID:php-nik,項目名稱:core,代碼行數:9,代碼來源:AdminComponent.php

示例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 . ' ...');
 }
開發者ID:phpffcms,項目名稱:ffcms-core,代碼行數:15,代碼來源:Response.php

示例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;
         }
     }
 }
開發者ID:searchblox,項目名稱:drupal-searchblox,代碼行數:12,代碼來源:SecondStepForm.php

示例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();
     }
 }
開發者ID:italolelis,項目名稱:wunderlist,代碼行數:12,代碼來源:OAuthLibAuthentication.php

示例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();
 }
開發者ID:ceko,項目名稱:concrete5-1,代碼行數:13,代碼來源:RedirectResponse.php

示例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();
     }
 }
開發者ID:QuangDang212,項目名稱:roadiz,代碼行數:21,代碼來源:AccessDeniedHandler.php

示例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();
     }
 }
開發者ID:alex63530,項目名稱:thelia,代碼行數:14,代碼來源:Redirect.php

示例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();
         }
     }
 }
開發者ID:nvvetal,項目名稱:gnomek,代碼行數:17,代碼來源:AuthListener.php

示例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;
         }
     }
 }
開發者ID:searchblox,項目名稱:drupal-searchblox,代碼行數:17,代碼來源:FirstStepForm.php

示例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;
}
開發者ID:zenmagick,項目名稱:zenmagick,代碼行數:27,代碼來源:redirect.php

示例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;
             }
         }
     }
 }
開發者ID:searchblox,項目名稱:drupal-searchblox,代碼行數:19,代碼來源:ThirdStepForm.php

示例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;
 }
開發者ID:italolelis,項目名稱:wunderlist,代碼行數:19,代碼來源:LeagueAuthentication.php


注:本文中的Symfony\Component\HttpFoundation\RedirectResponse::send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。