当前位置: 首页>>代码示例>>PHP>>正文


PHP Event\GetResponseEvent类代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent类的具体用法?PHP GetResponseEvent怎么用?PHP GetResponseEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GetResponseEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     //GOAL:
     // Redirect all incoming requests to their /locale/route equivlent as long as the route will exists when we do so.
     // Do nothing if it already has /locale/ in the route to prevent redirect loops
     $request = $event->getRequest();
     $path = $request->getPathInfo();
     $route_exists = false;
     //by default assume route does not exist.
     foreach ($this->routeCollection as $routeObject) {
         $routePath = $routeObject->getPath();
         if ($routePath == "/{_locale}" . $path) {
             $route_exists = true;
             break;
         }
     }
     //If the route does indeed exist then lets redirect there.
     if ($route_exists == true) {
         //Get the locale from the users browser.
         $locale = $request->getPreferredLanguage();
         //If no locale from browser or locale not in list of known locales supported then set to defaultLocale set in config.yml
         if ($locale == "" || $this->isLocaleSupported($locale) == false) {
             $locale = $request->getDefaultLocale();
         }
         $event->setResponse(new RedirectResponse("/" . $locale . $path));
     }
     //Otherwise do nothing and continue on~
 }
开发者ID:shitikovkirill,项目名称:MedTestPHP,代码行数:28,代码来源:LocaleRewriteListener.php

示例2: handle

 public function handle(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     // there may not be authentication information on this request
     if (!$request->headers->has('Authorization')) {
         return;
     }
     return;
     // format should be "Authorization: token ABCDEFG"
     $tokenString = 'HARDCODED';
     if (!$tokenString) {
         // there's no authentication info for us to process
         return;
     }
     // create an object that just exists to hold onto the token string for us
     $token = new ApiAuthToken();
     $token->setAuthToken($tokenString);
     $returnValue = $this->authenticationManager->authenticate($token);
     if ($returnValue instanceof TokenInterface) {
         return $this->securityContext->setToken($returnValue);
     }
 }
开发者ID:emiliand,项目名称:rest,代码行数:25,代码来源:ApiTokenListener.php

示例3: onRequest

 /**
  * Sets the AJAX parameter from the current request.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The response event, which contains the current request.
  */
 public function onRequest(GetResponseEvent $event)
 {
     // Pass to the Html class that the current request is an Ajax request.
     if ($event->getRequest()->request->get(static::AJAX_REQUEST_PARAMETER)) {
         Html::setIsAjax(TRUE);
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:13,代码来源:AjaxResponseSubscriber.php

示例4: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         try {
             $controller = $event->getRequest()->attributes->get('_controller');
             if (strstr($controller, '::')) {
                 //Check if its a "real controller" not assetic for example
                 $generatorYaml = $this->getGeneratorYml($controller);
                 $generator = $this->getGenerator($generatorYaml);
                 $generator->setGeneratorYml($generatorYaml);
                 $generator->setBaseGeneratorName($this->getBaseGeneratorName($controller));
                 $generator->build();
             }
         } catch (NotAdminGeneratedException $e) {
             //Lets the word running this is not an admin generated module
         }
     }
     if ($this->container->hasParameter('admingenerator.twig')) {
         $twig_params = $this->container->getParameter('admingenerator.twig');
         if (isset($twig_params['date_format'])) {
             $this->container->get('twig')->getExtension('core')->setDateFormat($twig_params['date_format'], '%d days');
         }
         if (isset($twig_params['number_format'])) {
             $this->container->get('twig')->getExtension('core')->setNumberFormat($twig_params['number_format']['decimal'], $twig_params['number_format']['decimal_point'], $twig_params['number_format']['thousand_separator']);
         }
     }
 }
开发者ID:Restless-ET,项目名称:GeneratorBundle,代码行数:27,代码来源:ControllerListener.php

示例5: handleEvent

 private function handleEvent(GetResponseEvent $event)
 {
     /** @var SessionHandler $sessionHandler */
     $sessionHandler = $this->container->get('ra.security.authentication.session_handler');
     // reinstate the token from the session. Could be expanded with logout check if needed
     if ($this->getTokenStorage()->getToken()) {
         return;
     }
     /** @var SamlInteractionProvider $samlInteractionProvider */
     $samlInteractionProvider = $this->container->get('ra.security.authentication.saml');
     if (!$samlInteractionProvider->isSamlAuthenticationInitiated()) {
         $sessionHandler->setCurrentRequestUri($event->getRequest()->getUri());
         $event->setResponse($samlInteractionProvider->initiateSamlRequest());
         /** @var SamlAuthenticationLogger $logger */
         $logger = $this->container->get('surfnet_saml.logger')->forAuthentication($sessionHandler->getRequestId());
         $logger->notice('Sending AuthnRequest');
         return;
     }
     /** @var SamlAuthenticationLogger $logger */
     $logger = $this->container->get('surfnet_saml.logger')->forAuthentication($sessionHandler->getRequestId());
     $expectedInResponseTo = $sessionHandler->getRequestId();
     try {
         $assertion = $samlInteractionProvider->processSamlResponse($event->getRequest());
     } catch (PreconditionNotMetException $e) {
         $logger->notice(sprintf('SAML response precondition not met: "%s"', $e->getMessage()));
         $event->setResponse($this->renderPreconditionExceptionResponse($e));
         return;
     } catch (Exception $e) {
         $logger->error(sprintf('Failed SAMLResponse Parsing: "%s"', $e->getMessage()));
         throw new AuthenticationException('Failed SAMLResponse parsing', 0, $e);
     }
     if (!InResponseTo::assertEquals($assertion, $expectedInResponseTo)) {
         $logger->error('Unknown or unexpected InResponseTo in SAMLResponse');
         throw new AuthenticationException('Unknown or unexpected InResponseTo in SAMLResponse');
     }
     $logger->notice('Successfully processed SAMLResponse, attempting to authenticate');
     $loaResolutionService = $this->container->get('surfnet_stepup.service.loa_resolution');
     $loa = $loaResolutionService->getLoa($assertion->getAuthnContextClassRef());
     $token = new SamlToken($loa);
     $token->assertion = $assertion;
     /** @var AuthenticationProviderManager $authenticationManager */
     $authenticationManager = $this->container->get('security.authentication.manager');
     try {
         $authToken = $authenticationManager->authenticate($token);
     } catch (BadCredentialsException $exception) {
         $logger->error(sprintf('Bad credentials, reason: "%s"', $exception->getMessage()), ['exception' => $exception]);
         $event->setResponse($this->renderBadCredentialsResponse($exception));
         return;
     } catch (AuthenticationException $failed) {
         $logger->error(sprintf('Authentication Failed, reason: "%s"', $failed->getMessage()), ['exception' => $failed]);
         $event->setResponse($this->renderAuthenticationExceptionResponse($failed));
         return;
     }
     // for the current request
     $this->getTokenStorage()->setToken($authToken);
     // migrate the session to prevent session hijacking
     $sessionHandler->migrate();
     $event->setResponse(new RedirectResponse($sessionHandler->getCurrentRequestUri()));
     $logger->notice('Authentication succeeded, redirecting to original location');
 }
开发者ID:eefjevanderharst,项目名称:Stepup-RA,代码行数:60,代码来源:SamlListener.php

示例6: onKernelRequest

 /**
  * Start collecting at the beginning of a request
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || !$this->driver || !$this->repository->isEnabled()) {
         return;
     }
     $this->driver->start();
 }
开发者ID:vipsoft,项目名称:code-coverage-bundle,代码行数:12,代码来源:RequestListener.php

示例7: purlCheckNodeContext

 /**
  * Checks if a node's type requires a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function purlCheckNodeContext(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher_interface)
 {
     $route_options = $this->routeMatch->getRouteObject()->getOptions();
     $isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
     if (!$isAdminRoute && ($matched = $this->matchedModifiers->getMatched() && ($entity = $this->routeMatch->getParameter('node')))) {
         $node_type = $this->entityStorage->load($entity->bundle());
         $purl_settings = $node_type->getThirdPartySettings('purl');
         if (!isset($purl_settings['keep_context']) || !$purl_settings['keep_context']) {
             $url = \Drupal\Core\Url::fromRoute($this->routeMatch->getRouteName(), $this->routeMatch->getRawParameters()->all(), ['host' => Settings::get('purl_base_domain'), 'absolute' => TRUE]);
             try {
                 $redirect_response = new TrustedRedirectResponse($url->toString());
                 $redirect_response->getCacheableMetadata()->setCacheMaxAge(0);
                 $modifiers = $event->getRequest()->attributes->get('purl.matched_modifiers', []);
                 $new_event = new ExitedContextEvent($event->getRequest(), $redirect_response, $this->routeMatch, $modifiers);
                 $dispatcher_interface->dispatch(PurlEvents::EXITED_CONTEXT, $new_event);
                 $event->setResponse($new_event->getResponse());
                 return;
             } catch (RedirectLoopException $e) {
                 \Drupal::logger('redirect')->warning($e->getMessage());
                 $response = new Response();
                 $response->setStatusCode(503);
                 $response->setContent('Service unavailable');
                 $event->setResponse($response);
                 return;
             }
         }
     }
 }
开发者ID:activelamp,项目名称:purl-d8,代码行数:34,代码来源:PurlNodeContextRoutes.php

示例8: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $request->setDefaultLocale($this->defaultLocale);
     $this->setLocale($request);
     $this->setRouterContext($request);
 }
开发者ID:saj696,项目名称:pipe,代码行数:7,代码来源:LocaleListener.php

示例9: onRequest

 /**
  * Add JSON handler to Whoops if Ajax request
  *
  * @param GetResponseEvent $event
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest() || !$event->getRequest()->isXmlHttpRequest()) {
         return;
     }
     $this->whoops->pushHandler(new JsonResponseHandler());
 }
开发者ID:robbert-vdh,项目名称:bolt,代码行数:12,代码来源:WhoopsListener.php

示例10: onRequest

 /**
  * Get data from request and create Pagination and PartialResponse events.
  * @param  GetResponseEvent $event Event object with request
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     $pagination = new Pagination();
     $partialResponse = new PartialResponse();
     if ($request->query->has('page')) {
         $pagination->setPage($request->query->get('page'));
     }
     if ($request->query->has('sort')) {
         $pagination->setSort($request->query->get('sort'));
     }
     if ($request->query->has('items_per_page')) {
         $pagination->setItemsPerPage($request->query->get('items_per_page'));
     }
     if ($request->query->has('fields')) {
         $partialResponse->setFields($request->query->get('fields'));
     }
     $this->paginatorService->setPagination($pagination);
     $this->paginatorService->setPartialResponse($partialResponse);
     /**
      * Append all used parameters from get and post
      */
     $this->paginatorService->setUsedRouteParams(array_merge($request->query->all(), $request->request->all()));
 }
开发者ID:nidzix,项目名称:Newscoop,代码行数:31,代码来源:PaginationListener.php

示例11: handle

 /**
  * Handles remember-me cookie based authentication.
  *
  * @param GetResponseEvent $event A GetResponseEvent instance
  */
 public function handle(GetResponseEvent $event)
 {
     if (null !== $this->securityContext->getToken()) {
         return;
     }
     $request = $event->getRequest();
     if (null === ($token = $this->rememberMeServices->autoLogin($request))) {
         return;
     }
     try {
         $token = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($token);
         if (null !== $this->dispatcher) {
             $loginEvent = new InteractiveLoginEvent($request, $token);
             $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent);
         }
         if (null !== $this->logger) {
             $this->logger->debug('SecurityContext populated with remember-me token.');
         }
     } catch (AuthenticationException $failed) {
         if (null !== $this->logger) {
             $this->logger->warn('SecurityContext not populated with remember-me token as the' . ' AuthenticationManager rejected the AuthenticationToken returned' . ' by the RememberMeServices: ' . $failed->getMessage());
         }
         $this->rememberMeServices->loginFail($request);
     }
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:31,代码来源:RememberMeListener.php

示例12: switchLocaleOnRequest

 /**
  * Checks if after a reload if the locale has changed.
  * If the user is logged in, the route is the default application route and the locale has changed,
  * the user locale will be modified
  *
  * @param GetResponseEvent $event
  */
 public function switchLocaleOnRequest(GetResponseEvent $event)
 {
     // no user is set in the access token
     // which means that no system user is authenticated and
     // that trigger is irrelevant
     if (null === ($user = $this->userFetcher->resolve())) {
         return;
     }
     $userLocale = $user->getSimpleProfile()->getLocale();
     if ($userLocale === ($cookie = $event->getRequest()->cookies->get('locale'))) {
         return;
     }
     $validLocale = true;
     try {
         $user->changeUserLocale($cookie);
     } catch (ChangeUserLocaleException $ex) {
         $validLocale = false;
         $request = $event->getRequest();
         $request->cookies->remove('locale');
         $request->setLocale($userLocale);
         $request->attributes->set('_locale', $userLocale);
     }
     // if the locale is invalid,
     // the cookie will be fixed in the response event
     if (!$validLocale) {
         $this->fixCookie = true;
         return;
     }
     $this->userRepository->modify($user);
 }
开发者ID:thesoftwarefactoryuk,项目名称:SenNetwork,代码行数:37,代码来源:ProfileLanguageListener.php

示例13: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST && $request->getMethod() == 'POST') {
         if (stripos($request->getPathInfo(), '/mapi') === 0) {
             return;
         }
         if (stripos($request->getPathInfo(), '/hls') === 0) {
             return;
         }
         $whiteList = array('/coin/pay/return/alipay', '/coin/pay/notify/alipay', '/coin/pay/notify/wxpay', '/pay/center/pay/alipay/return', '/pay/center/pay/wxpay/notify', '/pay/center/pay/alipay/notify', '/live/verify', '/course/order/pay/alipay/notify', '/vip/pay_notify/alipay', '/uploadfile/upload', '/uploadfile/cloud_convertcallback', '/uploadfile/cloud_convertcallback2', '/uploadfile/cloud_convertcallback3', '/uploadfile/cloud_convertheadleadercallback', '/disk/upload', '/file/upload', '/editor/upload', '/disk/convert/callback', '/partner/phpwind/api/notify', '/partner/discuz/api/notify', '/live/auth', '/edu_cloud/sms_callback');
         if (in_array($request->getPathInfo(), $whiteList)) {
             return;
         }
         if ($request->isXmlHttpRequest()) {
             $token = $request->headers->get('X-CSRF-Token');
         } else {
             $token = $request->request->get('_csrf_token', '');
         }
         $request->request->remove('_csrf_token');
         $expectedToken = $this->container->get('form.csrf_provider')->generateCsrfToken('site');
         if ($token != $expectedToken) {
             // @todo 需要区分ajax的response
             if ($request->getPathInfo() == '/admin') {
                 $token = $request->request->get('token');
                 $result = ServiceKernel::instance()->createService('CloudPlatform.AppService')->repairProblem($token);
                 $this->container->set('Topxia.RepairProblem', $result);
             } else {
                 $response = $this->container->get('templating')->renderResponse('TopxiaWebBundle:Default:message.html.twig', array('type' => 'error', 'message' => '页面已过期,请重新提交数据!', 'goto' => '', 'duration' => 0));
                 $event->setResponse($response);
             }
         }
     }
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:34,代码来源:KernelRequestListener.php

示例14: onKernelRequest

 /**
  * onKernelRequest
  * 
  * @access public
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $siteManager = $this->getSiteManager();
     $domain = $event->getRequest()->server->get('SERVER_NAME');
     if (!$siteManager->getCurrentSite()) {
         $site = $siteManager->findSiteByDomain($domain);
         if ($site) {
             $siteManager->setCurrentSite($site);
         } else {
             if ($this->getConfigurationManager()->has('core.default_admin_site')) {
                 $defaultSite = $this->getConfigurationManager()->get('core.default_admin_site');
                 if ($defaultSite) {
                     $site = $siteManager->findSiteById($defaultSite);
                     if ($site) {
                         $siteManager->setCurrentSite($site);
                         return $site;
                     }
                 }
             }
         }
     }
     if ($this->getSecurityContext()->isGranted('ROLE_ADMIN')) {
         if (!$siteManager->getCurrentAdminSite() && $siteManager->getCurrentSite()) {
             $siteManager->setCurrentAdminSite($siteManager->getCurrentSite());
         }
     }
 }
开发者ID:splicedmedia,项目名称:cms-bundle,代码行数:33,代码来源:HttpKernelListener.php

示例15: onKernelRequest

 /**
  * Set default timezone/locale
  *
  * @param GetResponseEvent $event
  *
  * @return void
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     // Set the user's default locale
     $request = $event->getRequest();
     if (!$request->hasPreviousSession()) {
         return;
     }
     $currentUser = $this->factory->getUser();
     //set the user's timezone
     if (is_object($currentUser)) {
         $tz = $currentUser->getTimezone();
     }
     if (empty($tz)) {
         $tz = $this->params['default_timezone'];
     }
     date_default_timezone_set($tz);
     if (!($locale = $request->attributes->get('_locale'))) {
         if (is_object($currentUser)) {
             $locale = $currentUser->getLocale();
         }
         if (empty($locale)) {
             $locale = $this->params['locale'];
         }
     }
     $request->setLocale($locale);
     // Set a cookie with session name for CKEditor's filemanager
     $sessionName = $request->cookies->get('mautic_session_name');
     if ($sessionName != session_name()) {
         /** @var \Mautic\CoreBundle\Helper\CookieHelper $cookieHelper */
         $cookieHelper = $this->factory->getHelper('cookie');
         $cookieHelper->setCookie('mautic_session_name', session_name(), null);
     }
 }
开发者ID:woakes070048,项目名称:mautic,代码行数:40,代码来源:CoreSubscriber.php


注:本文中的Symfony\Component\HttpKernel\Event\GetResponseEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。