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


PHP FilterControllerEvent::getController方法代码示例

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


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

示例1: onControllerFound

 public function onControllerFound(FilterControllerEvent $event)
 {
     if (!is_array($controllerData = $event->getController())) {
         return;
     }
     $controllerData = $event->getController();
     if ($controllerData[0] === null) {
         return;
     }
     $method = new \ReflectionMethod($controllerData[0], $controllerData[1]);
     //First we check for an automatic optim
     $annotations = $this->annotationReader->getMethodAnnotations($method);
     if (!empty($annotations)) {
         foreach ($annotations as $annotation) {
             if ($annotation instanceof SEOAnnotation\MetaTag) {
                 $request = $controllerData[0]->getRequest();
                 $controller = $request->get('_controller');
                 $object = $request->attributes->get($annotation->value);
                 if (empty($object)) {
                     continue;
                 }
                 $class = new \ReflectionClass($object);
                 $exists = $this->doctrine->getManager()->getRepository('SEOBundle:MetaTagPattern')->findOneBy(['controller' => $controller, 'entityClass' => $class->getName()]);
                 if (!is_null($exists)) {
                     $title = $this->getMeta('title', $object);
                     if ($title !== '') {
                         $this->sonataSEO->setTitle($title);
                     }
                     $meta = $this->getMeta('description', $object);
                     if ($meta !== '') {
                         $this->sonataSEO->addMeta('name', 'description', $meta);
                     }
                     $meta = $this->getMeta('keywords', $object);
                     if ($meta !== '') {
                         $this->sonataSEO->addMeta('name', 'keywords', $meta);
                     }
                 }
             }
         }
     }
     //Then we check an override with a manual optimisation
     $path = $event->getRequest()->getPathinfo();
     if (preg_match('@\\.[js|css]@', $path)) {
         return;
     }
     $optim = $this->doctrine->getManager()->getRepository('SEOBundle:MetaTag')->findOneBy(['url' => $path]);
     if ($optim !== null) {
         if ($optim->getMetaTitle() !== null) {
             $this->sonataSEO->setTitle($optim->getMetaTitle());
         }
         if ($optim->getMetaDescription() !== null) {
             $this->sonataSEO->addMeta('name', 'description', $optim->getMetaDescription());
         }
         if ($optim->getMetaKeywords() !== null) {
             $this->sonataSEO->addMeta('name', 'keywords', $optim->getMetaKeywords());
         }
     }
 }
开发者ID:alpixel,项目名称:AlpixelSeoBundle,代码行数:58,代码来源:MetaTagService.php

示例2: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $this->controllers[$event->getRequest()] = $event->getController();
     if ($parentRequestAttributes = $event->getRequest()->attributes->get('_forwarded')) {
         if ($parentRequestAttributes instanceof ParameterBag) {
             $parentRequestAttributes->set('_forward_controller', $event->getController());
         }
     }
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:9,代码来源:RequestDataCollector.php

示例3: onKernelController

 /**
  * http://api.symfony.com/2.4/Symfony/Component/HttpKernel/Event/FilterControllerEvent.html
  * 
  * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
  * @return type
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Request object
     $seesion = $request->getSession();
     $container = $this->container;
     if (!is_array($controller = $event->getController())) {
         return;
     }
     //if ($request->get('id') || $request->get('keyword')) {
     $entity = new Tracking();
     $entity->setController(get_class($controller[0]));
     // controller Formation\Bundle\Controller\PageController
     $entity->setAction($controller[1]);
     // getNextPageAction getPreviousPageAction
     $entity->setHttpMethod($request->getMethod());
     $entity->setIpRequest($request->getClientIp());
     $entity->setIdRequest($request->get('id'));
     $entity->setLang($seesion->get('_locale'));
     $entity->setPageRequest($request->get('page'));
     $entity->setKeywordRequest($request->get('keyword'));
     $entity->setUriRequest($request->getUri());
     $entity->setQueryRequest($request->getQueryString());
     $entity->setPathInfo($request->getPathInfo());
     $date = new \DateTime('now');
     $entity->setCreated($date);
     $em = $container->get('doctrine')->getManager();
     if ($container->get('security.context')->getToken() && $container->get('security.context')->getToken()->getUser()) {
         if (is_object($container->get('security.context')->getToken()->getUser())) {
             $user_id = $container->get('security.context')->getToken()->getUser()->getId();
             $user = $em->getRepository('UserBundle:User')->find($user_id);
             $entity->setUser($user);
             $last_acces = $em->getRepository('TrackingBundle:Tracking')->getLastAccess($user_id);
             // update last access duration
             if (is_object($last_acces)) {
                 //exit(\Doctrine\Common\Util\Debug::dump($last_acces->getCreated()));
                 $now = new \DateTime('now');
                 $diff = $now->getTimestamp() - $last_acces->getCreated()->getTimestamp();
                 $interval = new \DateTime();
                 $interval->setTimestamp($diff);
                 $tracking_id = $last_acces->getId();
                 $tracking = $em->getRepository('TrackingBundle:Tracking')->find($tracking_id);
                 $tracking->setDuration($interval);
                 //exit(\Doctrine\Common\Util\Debug::dump(strtotime($last_acces->getCreated()->format("Y-m-d H:i:s"))));
                 //$em->flush();
             }
             // update formation progression
             // case 1 : Formation\Bundle\Controller\ChapterController && action=showAction && id_request
             // get total formation page, get fos_user_formation percent, update percent
             // case 2 : Formation\Bundle\Controller\PageController && action=getNextPageAction or action=getPreviousPageAction && id_request
             // get total formation page
         }
     }
     $em->persist($entity);
     $em->flush();
     //var_dump($last_acces->getCreated());
     //var_dump($now);
     //exit(\Doctrine\Common\Util\Debug::dump($interval));
     //}
 }
开发者ID:scheffershen,项目名称:a-symfony2-richmedia-cms,代码行数:66,代码来源:VideoRequestListener.php

示例4: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (isset($controller[0]) && is_object($controller[0])) {
         $controller[0]->preAction();
     }
 }
开发者ID:kodazzi,项目名称:framework,代码行数:7,代码来源:ControllerListener.php

示例5: onKernelController

 /**
  * Core controller handler.
  *
  * @param FilterControllerEvent $event
  *
  * @throws \InvalidArgumentException
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
         return;
     }
     $paramFetcher = $this->container->get('fos_rest.request.param_fetcher');
     $controller = $event->getController();
     if (is_callable($controller) && method_exists($controller, '__invoke')) {
         $controller = [$controller, '__invoke'];
     }
     $paramFetcher->setController($controller);
     $attributeName = $this->getAttributeName($controller);
     $request->attributes->set($attributeName, $paramFetcher);
     if ($this->setParamsAsAttributes) {
         $params = $paramFetcher->all();
         foreach ($params as $name => $param) {
             if ($request->attributes->has($name) && null !== $request->attributes->get($name)) {
                 $msg = sprintf("ParamFetcher parameter conflicts with a path parameter '{$name}' for route '%s'", $request->attributes->get('_route'));
                 throw new \InvalidArgumentException($msg);
             }
             $request->attributes->set($name, $param);
         }
     }
 }
开发者ID:AAstakhov,项目名称:FOSRestBundle,代码行数:32,代码来源:ParamFetcherListener.php

示例6: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $instance = $controller[0];
     if (!$instance instanceof \Dinnovos\Amazonas\Controllers\InstallController) {
         $instance->settings = \Settings::prepareSettings();
         $instance->addMethod(function ($label, $default = -1) use($instance) {
             if (isset($instance->settings[$label])) {
                 return $instance->settings[$label];
             }
             return $default === -1 ? null : $default;
         }, "getSetting");
     }
     $instance->addMethod(function () use($instance) {
         return $instance->forward('Dinnovos\\Amazonas:Errors:error402');
     }, "responseError402");
     $instance->addMethod(function () use($instance) {
         return $instance->forward('Dinnovos\\Amazonas:Errors:error404');
     }, "responseError404");
     $instance->addMethod(function () use($instance) {
         return $instance->forward('Dinnovos\\Amazonas:Errors:error405');
     }, "responseError402");
     $instance->addMethod(function () use($instance) {
         return $instance->forward('Dinnovos\\Amazonas:Errors:error423');
     }, "responseError423");
 }
开发者ID:kodazzi,项目名称:amazonas,代码行数:26,代码来源:ShortcutsListener.php

示例7: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $object = new \ReflectionObject($controller[0]);
     $method = $object->getMethod($controller[1]);
     $classConfigurations = $this->reader->getClassAnnotations($object);
     $methodConfigurations = $this->reader->getMethodAnnotations($method);
     foreach (array_merge($classConfigurations, $methodConfigurations) as $configuration) {
         if ($configuration instanceof OAuth2) {
             $token = $this->token_storage->getToken();
             // If no access token is found by the firewall, then returns an authentication error
             if (!$token instanceof OAuth2Token) {
                 $this->createAuthenticationException($event, 'OAuth2 authentication required');
                 return;
             }
             foreach ($this->getCheckers() as $checker) {
                 $result = $checker->check($token, $configuration);
                 if (null !== $result) {
                     $this->createAccessDeniedException($event, $result);
                     return;
                 }
             }
         }
     }
 }
开发者ID:spomky-labs,项目名称:oauth2-server-bundle,代码行数:27,代码来源:AnnotationDriver.php

示例8: onCoreController

    /**
     * Guesses the template name to render and its variables and adds them to 
     * the request object.
     *
     * @param FilterControllerEvent $event A FilterControllerEvent instance
     */
    public function onCoreController(FilterControllerEvent $event)
    {
        if (!is_array($controller = $event->getController())) {
            return;
        }

        $request = $event->getRequest();

        if (!$configuration = $request->attributes->get('_tal')) {
//echo "PAS DE _TAL";
            return;
        }


        if (!$configuration->getTemplate()) {
            $configuration->setTemplate($this->guessTemplateName($controller, $request, $configuration->getExtension() ));
        }

        $request->attributes->set('_tal', $configuration->getTemplate());
        $request->attributes->set('_tal_vars', $configuration->getVars());
        //$request->attributes->set('_tal_extension', $configuration->getExtension());


        // all controller method arguments
        if (!$configuration->getVars()) {
            $r = new \ReflectionObject($controller[0]);

            $vars = array();
            foreach ($r->getMethod($controller[1])->getParameters() as $param) {
                $vars[] = $param->getName();
            }

            $request->attributes->set('_tal_vars', $vars);
        }
    }
开发者ID:neni,项目名称:NeniPhptalBundle,代码行数:41,代码来源:TalListener.php

示例9: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if (!$this->securityContext->getToken()) {
         return true;
     }
     $controller = $event->getController();
     list($object, $method) = $controller;
     $className = ClassUtils::getRealClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $classAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
     $methodsAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
     $allAnnotations = array_merge($classAnnotations, $methodsAnnotations);
     $ruleAnnotations = array_filter($allAnnotations, function ($annotation) {
         return $annotation instanceof Rule;
     });
     foreach ($ruleAnnotations as $ruleAnnotation) {
         if (is_array($ruleAnnotation->rules)) {
             $rules = $ruleAnnotation->rules;
         } else {
             $rules = explode(',', $ruleAnnotation->rules);
         }
         foreach ($rules as $rule) {
             $rule = trim($rule);
             if (empty($rule)) {
                 continue;
             }
             if ($this->securityContext->isGranted($rule)) {
                 return true;
             }
         }
     }
     throw new AccessDeniedException('The current user has no permissions on this action.');
 }
开发者ID:kassner,项目名称:auth-bundle,代码行数:34,代码来源:ControllerListener.php

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

示例11: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $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;
     }
     $request = $event->getRequest();
     $url = $request->getBaseUrl();
     if (in_array($url, self::$skipAuthentification)) {
         return;
     }
     $content = $request->getContent();
     $input = json_decode($content, true);
     // check authentification
     $account = $this->em->getRepository('AppBundle:Account')->getAccount($input['username'], $input['password']);
     if ($account == null) {
         throw new ApiAuthentificationFailureException("Ce compte n'existe pas");
     } else {
         if (in_array($url, self::$adminUrls) && $account->getUsername() != "admin") {
             throw new ApiAuthentificationFailureException("Ce compte n'est pas administrateur");
         }
         // mettre ces variables déjà calculées à disposition de tous les controlleurs
         $request->apiAccount = $account;
         $request->decodedBody = $input;
     }
 }
开发者ID:haterecoil,项目名称:zerowing,代码行数:31,代码来源:AuthentificationListener.php

示例12: onKernelController

 /**
  * Mark request with flag if handled with rest controller
  *
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $callable = $event->getController();
     if (is_array($callable) && count($callable) === 2 && $callable[0] instanceof RestController) {
         $event->getRequest()->attributes->set('__is_rest', true);
     }
 }
开发者ID:sunnyct,项目名称:silexcmf-rest,代码行数:12,代码来源:HttpKernelListener.php

示例13: getCalledMethod

 /**
  * Creates the method needed from the class- and method name
  *
  * @param FilterControllerEvent $event
  *
  * @return \ReflectionMethod
  */
 private function getCalledMethod(FilterControllerEvent $event)
 {
     list($object, $method) = $event->getController();
     $className = get_class($object);
     $reflectionClass = new \ReflectionClass($className);
     return $reflectionClass->getMethod($method);
 }
开发者ID:michaelzangerle,项目名称:RestValidationPlayground,代码行数:14,代码来源:KernelListener.php

示例14: onKernelController

 /**
  * Guesses the template name to render and its variables and adds them to
  * the request object.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $request = $event->getRequest();
     if (!($configuration = $request->attributes->get('_template'))) {
         return;
     }
     if (!$configuration->getTemplate()) {
         $guesser = $this->container->get('sensio_framework_extra.view.guesser');
         $configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
     }
     $request->attributes->set('_template', $configuration->getTemplate());
     $request->attributes->set('_template_vars', $configuration->getVars());
     $request->attributes->set('_template_streamable', $configuration->isStreamable());
     // all controller method arguments
     if (!$configuration->getVars()) {
         $r = new \ReflectionObject($controller[0]);
         $vars = array();
         foreach ($r->getMethod($controller[1])->getParameters() as $param) {
             $vars[] = $param->getName();
         }
         $request->attributes->set('_template_default_vars', $vars);
     }
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:32,代码来源:TemplateListener.php

示例15: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
     $object = new \ReflectionClass($className);
     $method = $object->getMethod($controller[1]);
     /**
      * @var UserType\UserTypeInterface[] $requiredUserTypes
      */
     $requiredUserTypes = array_merge($this->getConfigurations($this->reader->getClassAnnotations($object)), $this->getConfigurations($this->reader->getMethodAnnotations($method)));
     if (count($requiredUserTypes) === 0) {
         return;
     }
     $token = $this->securityContext->getToken();
     if (null === $token) {
         throw new AccessDeniedException(sprintf("You are not authenticated, a known user type is required for access."));
     }
     $user = $token->getUser();
     foreach ($requiredUserTypes as $userType) {
         $userClass = $userType->getUserClass();
         if (!interface_exists($userClass) && !class_exists($userClass)) {
             throw new RuntimeException(sprintf("The user type class '%s' does not exist", $userClass));
         }
         if (!$user instanceof $userClass) {
             throw new AccessDeniedException(sprintf("You do not have the required user type. A user type of '%s' is required.", $userClass));
         }
         unset($userType, $userClass);
     }
 }
开发者ID:viettut,项目名称:todo,代码行数:31,代码来源:UserTypeSecurityListener.php


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