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


PHP FilterControllerEvent::setController方法代码示例

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


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

示例1: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     if ('HealthCareAbroad\\SearchBundle\\Controller\\FrontendController::searchProcessAction' != $request->attributes->get('_controller')) {
         return;
     }
     $controllerAndAction = $event->getController();
     $controller = $controllerAndAction[0];
     $requestParams = $request->request->all();
     if (isset($requestParams['searchParameter']) && !empty($requestParams['searchParameter'])) {
         $event->setController(array($controller, 'searchProcessNarrowAction'));
         return;
     }
     $treatmentId = $request->get('treatment_id');
     $destinationId = $request->get('destination_id') == '0-0' ? 0 : $request->get('destination_id');
     $treatmentName = $request->get('sb_treatment');
     $destinationName = $request->get('sb_destination');
     //TODO: this will break if we are going to force the destination field in our search forms to always submit the ID
     if (!$treatmentId && !$destinationId || !$treatmentId && $treatmentName || !$destinationId && $destinationName) {
         $context = '';
         if ($treatmentName && $destinationName) {
             $context = 'combined';
         } elseif ($treatmentName) {
             $context = 'treatment';
         } elseif ($destinationName) {
             $context = 'destination';
         }
         $request->attributes->set('context', $context);
         $event->setController(array($controller, 'searchProcessKeywordsAction'));
         return;
     }
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:32,代码来源:ProcessSearchListener.php

示例2: onKernelController

 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     /**
      * @var $controller Controller
      */
     $controller = $event->getController();
     /*
      * $controller passed can be either a class or a Closure.
      * This is not usual in Symfony but it may happen.
      * If it is a class, it comes in array format
      */
     if (!is_array($controller)) {
         return;
     }
     if ($controller[0] instanceof ProductControllerInterface) {
         $user = $controller[0]->get('security.token_storage')->getToken()->getUser();
         // Checks if an order belongs to user
         $orderId = $event->getRequest()->get('orderId');
         if ($orderId) {
             $order = $this->entityManager->getRepository('IlluminatiOrderBundle:User_order')->findOneBy(['hostOrderId' => $orderId, 'usersId' => $user->getId(), 'deleted' => 0]);
             if (!$order) {
                 throw new NotFoundHttpException('Order not found!');
             }
             $redirectUrl = $controller[0]->generateUrl('host_order_summary', ['id' => $orderId]);
             $closeDate = $order->getHostOrderId()->getCloseDate();
             $now = new \DateTime('now');
             if ($closeDate < $now) {
                 $this->session->getFlashBag()->add('info', $this->translator->trans('product.order_expired'));
                 // redirect to summary if order is expired
                 $event->setController(function () use($redirectUrl) {
                     return new RedirectResponse($redirectUrl);
                 });
             }
             // redirect to summary if order is closed or confirmed
             if ($order->getHostOrderId()->getStateId() == 0) {
                 $this->session->getFlashBag()->add('info', $this->translator->trans('product.order_closed'));
                 $event->setController(function () use($redirectUrl) {
                     return new RedirectResponse($redirectUrl);
                 });
             }
         }
         // Load cart items from database
         $cart = $controller[0]->get('cart.provider');
         if ($cart->getStorage() === null) {
             $cart->load($user->getId(), $orderId);
         }
     }
 }
开发者ID:ernestre,项目名称:illuminati,代码行数:51,代码来源:ProductListener.php

示例3: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     $session = $event->getRequest()->getSession();
     /** @var BaseController $ctrl */
     $ctrl = $controller[0];
     if (!is_object($ctrl) || !$ctrl instanceof BaseController) {
         return;
     }
     // no loop for you, also allow username checking
     if ($ctrl instanceof ProfileController && ($controller[1] == 'updateUsernameAction' || $controller[1] == 'checkUsernameAction')) {
         return;
     }
     /** @var User $user */
     $user = $ctrl->getUser();
     if ($user && $this->isGUID($user->getUsername())) {
         $session->getFlashBag()->add('error', "We recently changed our username restrictions. Your previous username is no longer valid. Please create a new one.");
         $url = $this->router->generate('reset_username');
         $event->setController(function () use($url) {
             return new RedirectResponse($url);
         });
     }
 }
开发者ID:scottstuff,项目名称:GCProtractorJS,代码行数:26,代码来源:UnsetUsernameListener.php

示例4: onKernelController

 /**
  * This event will fire during any controller call.
  *
  * @param FilterControllerEvent $event
  *
  * @return type
  *
  * @throws AccessDeniedHttpException
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         //return if no controller
         return;
     }
     $object = new \ReflectionObject($controller[0]);
     // get controller
     $method = $object->getMethod($controller[1]);
     // get method
     $configurations = $this->reader->getMethodAnnotations($method);
     foreach ($configurations as $configuration) {
         //Start of annotations reading
         if (isset($configuration->grantType) && $controller[0] instanceof BaseProjectController) {
             //Found our annotation
             $controller[0]->setProjectGrantType($configuration->grantType);
             $request = $controller[0]->get('request_stack')->getCurrentRequest();
             $id = $request->get('id', false);
             if ($id !== false) {
                 $redirectUrl = $controller[0]->initAction($id, $configuration->grantType);
                 if ($redirectUrl) {
                     $event->setController(function () use($redirectUrl) {
                         return new RedirectResponse($redirectUrl);
                     });
                 }
             }
         }
     }
 }
开发者ID:sshversioncontrol,项目名称:git-web-client,代码行数:38,代码来源:ProjectAccessAnnotationDriver.php

示例5: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $annotation = $this->findAnnotation($controller);
     if (!$annotation) {
         return;
     }
     $lastTouched = $annotation->calculateLastModified($this->metaQueryFactory);
     if (!$lastTouched) {
         return;
     }
     $this->lastTouchedResults[$request] = $lastTouched;
     /*
      * Für kernel.debug = 1 senden wir niemals
      * 304-Responses, anstatt den Kernel auszuführen:
      *
      * Das Ergebnis hängt auch von vielen Dingen außerhalb
      * wfd_meta ab (z. B. template-Code), die wir hier nicht
      * berücksichtigen können.
      */
     if ($this->debug) {
         return;
     }
     $response = new Response();
     $response->setLastModified($lastTouched);
     if ($response->isNotModified($request)) {
         $event->setController(function () use($response) {
             return $response;
         });
     }
 }
开发者ID:webfactory,项目名称:wfdmeta-bundle,代码行数:32,代码来源:EventListener.php

示例6: onKernelController

 /**
  * Handles HTTP validation headers.
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     if (!($configuration = $request->attributes->get('_cache'))) {
         return;
     }
     $response = new Response();
     $lastModifiedDate = '';
     if ($configuration->getLastModified()) {
         $lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
         $response->setLastModified($lastModifiedDate);
     }
     $etag = '';
     if ($configuration->getETag()) {
         $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
         $response->setETag($etag);
     }
     if ($response->isNotModified($request)) {
         $event->setController(function () use($response) {
             return $response;
         });
     } else {
         if ($etag) {
             $this->etags[$request] = $etag;
         }
         if ($lastModifiedDate) {
             $this->lastModifiedDates[$request] = $lastModifiedDate;
         }
     }
 }
开发者ID:raphydev,项目名称:onep,代码行数:33,代码来源:HttpCacheListener.php

示例7: onKernelController

 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Check if the event has a nodeTranslation, if not this method can be skipped
     if (!$request->attributes->has('_nodeTranslation')) {
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     if (!$nodeTranslation instanceof NodeTranslation) {
         $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslation);
         $request->attributes->set('_nodeTranslation', $nodeTranslation);
     }
     $entity = $nodeTranslation->getRef($this->em);
     // If the entity is an instance of the SlugActionInterface, change the controller
     if ($entity instanceof SlugActionInterface) {
         $request->attributes->set('_entity', $entity);
         // Do security check by firing an event that gets handled by the SlugSecurityListener
         $securityEvent = new SlugSecurityEvent();
         $securityEvent->setNode($nodeTranslation->getNode())->setEntity($entity)->setRequest($request)->setNodeTranslation($nodeTranslation);
         $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);
         // Set the right controller
         $request->attributes->set('_controller', $entity->getControllerAction());
         $event->setController($this->resolver->getController($request));
     }
 }
开发者ID:Amrit01,项目名称:KunstmaanBundlesCMS,代码行数:28,代码来源:SlugListener.php

示例8: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if ($event->isMasterRequest()) {
         $route = $event->getRequest()->get('_route');
         if ($this->isExcludedRoute($route)) {
             return;
         }
         if ($this->isAsset($_SERVER['REQUEST_URI'])) {
             return;
         }
         $is_logged = $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY');
         if (!$is_logged && $route != 'fos_user_security_login') {
             $redirectUrl = $this->router->generate('fos_user_security_login');
             $event->setController(function () use($redirectUrl) {
                 return new RedirectResponse($redirectUrl);
             });
         }
         if (!$is_logged && $route == 'fos_user_security_login') {
             return;
         }
         if (!$this->rolesProvider->hasRouteAccess($route)) {
             throw new AccessDeniedException();
         }
     }
 }
开发者ID:sanborino,项目名称:clinica,代码行数:25,代码来源:AccessCheckerListener.php

示例9: environmentSessionController

 public function environmentSessionController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $session = new Session();
     $environment = $session->get('environment');
     // Validar si hay un environment cargado a la session de usuario
     if (isset($environment)) {
         // Validar si el controller es una instacia de InitController
         if ($controller[0] instanceof InitController) {
             // ****** if auth
             // ****** redirect home
             // ****** no
             // ****** redirect login
             return;
         }
         return;
     } else {
         // NO exite un environment cargado
         // Validar si el controller NO es instacia de InitController
         if (!$controller[0] instanceof InitController) {
             //redireccion a init controller
             $redirectUrl = '/init';
             $event->setController(function () use($redirectUrl) {
                 return new RedirectResponse($redirectUrl);
             });
         } else {
             return;
         }
     }
 }
开发者ID:stzef,项目名称:siacolweb-servicio,代码行数:30,代码来源:EnvironmentListener.php

示例10: it_set_controller_if_init_return_response

 public function it_set_controller_if_init_return_response(FilterControllerEvent $event, Request $request, SampleInitController $controller)
 {
     $event->getRequest()->willReturn($request);
     $event->getController()->willReturn(array($controller));
     $controller->init($request)->willReturn(new Response('http://example.com/'));
     $event->setController(Argument::allOf(Argument::withEntry('0', Argument::type('Yavin\\Symfony\\Controller\\InitControllerSubscriber')), Argument::withEntry('1', 'responseAction')))->shouldBeCalled();
     $this->onKernelController($event);
 }
开发者ID:yavin,项目名称:symfony-init-controller,代码行数:8,代码来源:InitControllerSubscriberSpec.php

示例11: environmentSessionController

 public function environmentSessionController(FilterControllerEvent $event)
 {
     $securityChecker = $this->container->get('security.authorization_checker');
     $controller = $event->getController();
     $session = new Session();
     $environment = $session->get('environment');
     $request = $event->getRequest();
     /*
     if ($request->get('_route') == '') {
     	$redirectInit = '/init';
     	$event->setController(function() use ($redirectInit) {
     			return new RedirectResponse($redirectInit);
     		});
     }
     */
     if (isset($environment)) {
         if ($controller[0] instanceof InitController) {
             if ($securityChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
                 $redirectUrl = '/menu';
                 $event->setController(function () use($redirectUrl) {
                     return new RedirectResponse($redirectUrl);
                 });
             } else {
                 if ($controller[0] instanceof SecurityController) {
                     return;
                 } else {
                     $environment = $session->remove('environment');
                     $redirectUrl = '/init';
                     $event->setController(function () use($redirectUrl) {
                         return new RedirectResponse($redirectUrl);
                     });
                 }
             }
         }
     } else {
         if (!$controller[0] instanceof InitController) {
             $redirectUrl = '/init';
             $event->setController(function () use($redirectUrl) {
                 return new RedirectResponse($redirectUrl);
             });
         } else {
             return;
         }
     }
 }
开发者ID:stzef,项目名称:siacolweb-app,代码行数:45,代码来源:EnvironmentListener.php

示例12: obtainScopes

 protected function obtainScopes(array $scopes, FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     $url = $this->scopeManager->obtainScopeUrl($scopes, $request->getRequestUri());
     // Set request parameter for redirect
     $request->attributes->set('url', '/' . ltrim($url, '/'));
     // Set controller to redirect controller instead
     $event->setController(array(new RedirectController(), 'redirectAction'));
 }
开发者ID:rmed19,项目名称:GoogleApiBundle,代码行数:9,代码来源:ControllerSubscriber.php

示例13: onController

 /**
  * Replaces the default controller action with one that provides data in one of the requested formats
  *
  * @param FilterControllerEvent $event
  */
 public function onController(FilterControllerEvent $event)
 {
     $this->event = $event;
     $types = $this->request->getAcceptableContentTypes();
     $controller = null;
     foreach ($types as $type) {
         if ($controller = $this->findControllerForContentType($type)) {
             $this->event->setController($controller);
             break;
         }
     }
     if (null === $controller) {
         header('HTTP/1.0 406 Not Acceptable');
         die;
     }
     $controller = $event->getController();
     $this->logger->debug('Chose controller action "' . array_pop($controller) . '"');
 }
开发者ID:elseym,项目名称:content-type-negotiation-bundle,代码行数:23,代码来源:ContentTypeNegotiator.php

示例14: filter

 public function filter(FilterControllerEvent $event, Response $response)
 {
     if ($this->check($response)) {
         $event->setController(function () use($response) {
             return $response;
         });
         $event->stopPropagation();
     }
 }
开发者ID:geschke,项目名称:legacy-integration-bundle,代码行数:9,代码来源:PassthruLegacyResponseFilter.php

示例15: onKernelController

 /**
  * Overriding response in Sandbox mode
  *
  * @param FilterControllerEvent $event
  * @throws \Exception
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     list($responseController, , , ) = $this->sandboxResponseManager->getResponseController($controller[0], $controller[1], $this->request->query, $this->request->request, $this->getStreamParams());
     // Fall back to real controller if none has been found and force mode is false
     if ($responseController === false) {
         return;
     }
     $event->setController($responseController);
 }
开发者ID:danrevah,项目名称:sandbox-bundle,代码行数:16,代码来源:SandboxListener.php


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