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


PHP FilterControllerEvent::getKernel方法代码示例

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


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

示例1: onKernelController

 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     // This controller implements ToolInterface? Then set the course/session
     if ($controller[0] instanceof ToolInterface) {
         //if ($controller[0] instanceof ToolBaseController) {
         //$token = $event->getRequest()->query->get('token');
         $kernel = $event->getKernel();
         $request = $event->getRequest();
         /** @var ContainerInterface $container */
         $container = $this->container;
         // Course
         // The 'course' variable example "123" for this URL: courses/123/
         $courseCode = $request->get('course');
         // Detect if the course was set with a cidReq:
         if (empty($courseCode)) {
             $courseCodeFromRequest = $request->get('cidReq');
             $courseCode = $courseCodeFromRequest;
         }
         /** @var EntityManager $em */
         $em = $container->get('doctrine')->getManager();
         $securityChecker = $container->get('security.authorization_checker');
         if (!empty($courseCode)) {
             /** @var Course $course */
             $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneByCode($courseCode);
             if ($course) {
                 // Session
                 $sessionId = $request->get('id_session');
                 if (empty($sessionId)) {
                     // Check if user is allowed to this course
                     // See CourseVoter.php
                     if (false === $securityChecker->isGranted(CourseVoter::VIEW, $course)) {
                         throw new AccessDeniedException('Unauthorised access to course!');
                     }
                 } else {
                     $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
                     if ($session) {
                         //$course->setCurrentSession($session);
                         $controller[0]->setSession($session);
                         $session->setCurrentCourse($course);
                         // Check if user is allowed to this course-session
                         // See SessionVoter.php
                         if (false === $securityChecker->isGranted(SessionVoter::VIEW, $session)) {
                             throw new AccessDeniedException('Unauthorised access to session!');
                         }
                     } else {
                         throw new NotFoundHttpException('Session not found');
                     }
                 }
                 // Example 'chamilo_notebook.controller.notebook:indexAction'
                 $controllerAction = $request->get('_controller');
                 $controllerActionParts = explode(':', $controllerAction);
                 $controllerNameParts = explode('.', $controllerActionParts[0]);
                 $controllerName = $controllerActionParts[0];
                 $toolName = null;
                 if (isset($controllerNameParts[1]) && $controllerNameParts[1] == 'controller') {
                     $toolName = $this->container->get($controllerName)->getToolName();
                     $action = str_replace('action', '', $controllerActionParts[1]);
                     $actionLabel = $toolName . '.' . $action;
                 }
                 $container->get('twig')->addGlobal('tool_name', $toolName);
                 // Legacy code
                 $courseInfo = api_get_course_info($course->getCode());
                 $container->get('twig')->addGlobal('course', $course);
                 $request->getSession()->set('_real_cid', $course->getId());
                 $request->getSession()->set('_cid', $course->getCode());
                 $request->getSession()->set('_course', $courseInfo);
                 /*
                 Sets the controller course in order to use $this->getCourse()
                 */
                 $controller[0]->setCourse($course);
             } else {
                 throw new NotFoundHttpException('Course not found');
             }
         }
     }
 }
开发者ID:par-orillonsoft,项目名称:chamilo-lms,代码行数:83,代码来源:CourseListener.php

示例2: onKernelController

 /**
  * Controller.
  *
  * @param FilterControllerEvent $event The event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $this->request = $event->getRequest();
     if (false === $this->isEnabled()) {
         return;
     }
     $controller = $event->getController();
     $metadata = $this->getControllerActionMetadata($controller);
     if (null === $metadata || 0 === count($metadata->param_converter_bag)) {
         // no annotations defined for this controller
         return;
     }
     foreach ($metadata->param_converter_bag as $param_converter) {
         $class = $param_converter->class;
         $bag = $param_converter->id_source;
         $unique_identifier = $request->{$bag}->get($param_converter->id_name, null);
         $entity = null;
         try {
             if (null === $unique_identifier) {
                 throw new \InvalidArgumentException('Unable to find identifier with provided attribute: ' . $param_converter->id_name);
             }
         } catch (\InvalidArgumentException $e) {
             if (true === $param_converter->required) {
                 throw $e;
             }
         }
         if (null !== $unique_identifier) {
             $entity = $event->getKernel()->getApplication()->getEntityManager()->find($class, $unique_identifier);
             if (null === $entity) {
                 throw new NotFoundHttpException("No `{$class}` exists with uid `{$unique_identifier}`.");
             }
         }
         $request->attributes->set($param_converter->name, $entity);
     }
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:40,代码来源:ParamConverterListener.php


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