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


PHP GetResponseEvent::isMasterRequest方法代码示例

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


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

示例1: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $this->logger->debug('Entity builder listener: catch kernel.request event');
     // If this is not a master request, skip handling
     if (!$event->isMasterRequest()) {
         $this->logger->debug('Entity builder listener: this is not master request, skip');
         return;
     }
     // If content already prepared
     if ($event->hasResponse()) {
         $this->logger->debug('Entity builder listener: event already has response, skip');
         return;
     }
     // Getting request
     $request = $event->getRequest();
     // Getting action
     $apiServerAction = $event->getRequest()->attributes->get('apiAction');
     /* @var $apiServerAction ApiServerAction */
     // Something wrong
     if (!$apiServerAction) {
         $this->logger->error('Request parser listener: request has no apiAction attribute, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // Creating request data entity
     try {
         $apiEntity = $apiServerAction->getRequestedEntity($request->attributes->get('apiData'));
     } catch (\Exception $e) {
         $this->logger->notice(sprintf('Request parser listener: unable to convert apiData to entity ("%s"), apiEntity set tu null', $e->getMessage()));
         $apiEntity = null;
     }
     // Setting request attributes
     $request->attributes->set('requestData', $apiEntity);
     // Cleaning request attributes
     $request->attributes->remove('apiData');
 }
开发者ID:leoza,项目名称:api-server-bundle,代码行数:35,代码来源:EntityBuilder.php

示例2: onKernelRequest

 /**
  * Logs master requests on event KernelEvents::REQUEST.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->logRequest($event->getRequest());
 }
开发者ID:opensourcerefinery,项目名称:vicus,代码行数:12,代码来源:LogListener.php

示例3: onRequest

 /**
  * 请求完成后执行
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $session = $request->getSession();
     // 如果有 OpenID,则放行
     if ($session->has('openid')) {
         return;
     }
     // 排除资源文件
     if (preg_match("^/(_(profiler|wdt)|css|images|js)/^", $request->getPathInfo())) {
         return;
     }
     // 排除不需要 openid 的 URL
     $currentRoute = $request->get('_route');
     $currentParams = $request->get('_route_params');
     if (in_array($currentRoute, $this->ignoreRoute)) {
         return;
     }
     // 跳转到授权页,并把当前页作为参数(授权完成后还要跳转回来)
     $currentUri = $this->router->generate($currentRoute, $currentParams);
     $authorizeUrl = $this->router->generate('wechat_authorize', ['continue' => $currentUri]);
     if (!$request->isXmlHttpRequest()) {
         return $event->setResponse(new RedirectResponse($authorizeUrl));
     }
     $response = new JsonResponse(['failure' => '401 Unauthorized', 'redirect' => $authorizeUrl]);
     return $event->setResponse($response);
 }
开发者ID:timy-life,项目名称:segments,代码行数:33,代码来源:SymfonyKernelOAuthContinue.php

示例4: 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

示例5: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     // Check master request
     if (!$event->isMasterRequest()) {
         return;
     }
     // Check excluded paths
     $path = $event->getRequest()->getPathInfo();
     if ($this->isExcludedPath($path)) {
         return;
     }
     // Extract token
     $headerToken = $this->tokenExtractor->extract($event->getRequest());
     if (!is_string($headerToken)) {
         throw new AuthenticationExpiredException('The access token is missing');
     }
     $token = $this->tokenVerificator->parsing($headerToken);
     // Validate token
     if (!$this->tokenVerificator->isValid($token)) {
         throw new AuthenticationExpiredException('The access token is invalid');
     }
     // Store token
     $this->tokenStorage->setToken($token);
     // token
     $operator = $token->getClaim('operatorId');
     $event->getRequest()->request->set('operator', $operator);
     $event->getRequest()->query->set('operator', $operator);
 }
开发者ID:sportnco,项目名称:TokenManagerBundle,代码行数:31,代码来源:RequestListener.php

示例6: onRequest

 /**
  * Resume the session if it has been started previously or debugging is enabled
  *
  * @param GetResponseEvent $event
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->manager->initialize($event->getRequest());
 }
开发者ID:gandalf3,项目名称:bolt,代码行数:12,代码来源:PagerListener.php

示例7: setThemeEngineRequestAttributes

 /**
  * The ThemeEngine::requestAttributes MUST be updated based on EACH Request and not only the initial Request.
  * @param GetResponseEvent $event
  */
 public function setThemeEngineRequestAttributes(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->themeEngine->setRequestAttributes($event->getRequest());
 }
开发者ID:Silwereth,项目名称:core,代码行数:11,代码来源:CreateThemedResponseListener.php

示例8: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     } else {
     }
 }
开发者ID:tikoutare,项目名称:sf2,代码行数:7,代码来源:RequestListener.php

示例9: handle

 /**
  * Reads the Security Token from the session.
  *
  * @param GetResponseEvent $event A GetResponseEvent instance
  */
 public function handle(GetResponseEvent $event)
 {
     if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
         $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
         $this->registered = true;
     }
     $request = $event->getRequest();
     $session = $request->hasPreviousSession() ? $request->getSession() : null;
     if (null === $session || null === ($token = $session->get($this->sessionKey))) {
         $this->tokenStorage->setToken(null);
         return;
     }
     $token = unserialize($token);
     if (null !== $this->logger) {
         $this->logger->debug('Read existing security token from the session.', array('key' => $this->sessionKey));
     }
     if ($token instanceof TokenInterface) {
         $token = $this->refreshUser($token);
     } elseif (null !== $token) {
         if (null !== $this->logger) {
             $this->logger->warning('Expected a security token from the session, got something else.', array('key' => $this->sessionKey, 'received' => $token));
         }
         $token = null;
     }
     $this->tokenStorage->setToken($token);
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:31,代码来源:ContextListener.php

示例10: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $routes = $this->router->getRouteCollection();
     $route = $routes->get($request->attributes->get('_route'));
     if (!$route->getOption('requires_license')) {
         return;
     }
     if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
         // Checking for whitelisted users
         try {
             $user = $this->tokenStorage->getToken()->getUser();
             $today = date('Y-m-d');
             if ($user instanceof UserInterface) {
                 $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                 foreach ($whitelist as $allowed) {
                     if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
                         return;
                     }
                 }
             }
         } catch (\Exception $e) {
             // Do nothing
         }
         $url = $this->router->generate('atlassian_connect_unlicensed');
         $response = new RedirectResponse($url);
         $event->setResponse($response);
     }
 }
开发者ID:sainthardaway,项目名称:atlassian-connect-bundle,代码行数:32,代码来源:LicenseListener.php

示例11: onKernelRequest

 /**
  * Logs master requests on event KernelEvents::REQUEST
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->logger->info('Received request');
 }
开发者ID:gmo,项目名称:common,代码行数:12,代码来源:HttpLogListener.php

示例12: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->sha = array();
 }
开发者ID:nelmio,项目名称:NelmioSecurityBundle,代码行数:7,代码来源:ContentSecurityPolicyListener.php

示例13: handle

 /**
  * Reads the SecurityContext from the session.
  *
  * @param GetResponseEvent $event A GetResponseEvent instance
  */
 public function handle(GetResponseEvent $event)
 {
     if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
         $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
         $this->registered = true;
     }
     $request = $event->getRequest();
     $session = $request->hasPreviousSession() ? $request->getSession() : null;
     if (null === $session || null === ($token = $session->get('_security_' . $this->contextKey))) {
         $this->context->setToken(null);
         return;
     }
     $token = unserialize($token);
     if (null !== $this->logger) {
         $this->logger->debug('Read SecurityContext from the session');
     }
     if ($token instanceof TokenInterface) {
         $token = $this->refreshUser($token);
     } elseif (null !== $token) {
         if (null !== $this->logger) {
             $this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token)));
         }
         $token = null;
     }
     $this->context->setToken($token);
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:31,代码来源:ContextListener.php

示例14: onRequest

 /**
  * On Request received check the validity of the webpack cache.
  *
  * @param GetResponseEvent $event the response to send to te browser, we don't we only ensure the cache is there.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->guard->rebuild();
 }
开发者ID:hostnet,项目名称:webpack-bundle,代码行数:12,代码来源:RequestListener.php

示例15: onRequest

 public function onRequest(GetResponseEvent $event)
 {
     $token = $this->storage->getToken();
     $request = $event->getRequest();
     $blackList = ['api.server.status', 'api.characters', 'api.character_create', 'template.serverstatus', 'api.character_create.validate', 'api.character_create.finalize', 'api.character.apicredentials', 'template.slidebutton', 'template.slidemenu'];
     if (!$event->isMasterRequest() || $token === null || in_array('ROLE_SUPER_ADMIN', $this->getRolesArray($token->getRoles())) || in_array($request->attributes->get('_route'), $blackList) || !strstr(explode('::', $request->attributes->get('_controller'))[0], 'AppBundle')) {
         $this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route')));
         return;
     }
     if ($request->attributes->get('_controller') === 'AppBundle\\Controller\\Admin\\CharacterController::indexAction' && $this->session->has(self::ACTIVE_API_CHECK)) {
         $this->session->getFlashBag()->add('danger', 'You must add a character with a valid NO EXPIRY API KEY in order to proceed');
         $this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route')));
         $this->session->remove(self::ACTIVE_API_CHECK);
         return;
     }
     if ($token->isAuthenticated() && ($user = $this->storage->getToken()->getUser()) instanceof User) {
         $characters = $this->doctrine->getRepository('AppBundle:Character')->findBy(['user' => $user]);
         $activeKeys = $this->doctrine->getRepository('AppBundle:ApiCredentials')->getActiveKeyForUser($user);
         if (count($characters) == 0 || count($activeKeys) <= 0) {
             $this->log->debug(sprintf('LISTENER REDIRECT for %s', $request->attributes->get('_route')));
             $response = new RedirectResponse($this->router->generate('characters'));
             $this->session->set(self::ACTIVE_API_CHECK, time());
             $event->setResponse($response);
         }
     }
 }
开发者ID:Remnant-Legion,项目名称:eau,代码行数:26,代码来源:_old_ActiveApiRequestListener.php


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