plugins/ExamPlugin/Listener/ExamManageAccessListener.php line 23

Open in your IDE?
  1. <?php
  2. namespace ExamPlugin\Listener;
  3. use AppBundle\Common\Exception\AccessDeniedException;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  6. use Symfony\Component\HttpKernel\HttpKernelInterface;
  7. use Topxia\Service\Common\ServiceKernel;
  8. class ExamManageAccessListener
  9. {
  10.     /**
  11.      * @var ContainerInterface
  12.      */
  13.     private $container;
  14.     public function __construct(ContainerInterface $container)
  15.     {
  16.         $this->container $container;
  17.     }
  18.     public function onKernelController(ControllerEvent $event)
  19.     {
  20.         if (HttpKernelInterface::MAIN_REQUEST != $event->getRequestType()) {
  21.             return;
  22.         }
  23.         $request $event->getRequest();
  24.         $currentUser ServiceKernel::instance()->getCurrentUser();
  25.         $requestPath $request->getPathInfo();
  26.         if (((=== stripos($requestPath'/exam/manage') && !$currentUser->hasPermission('admin_train_exam_manage_list')) || (=== stripos($requestPath'/exam/test_paper') && !$currentUser->hasPermission('admin_train_test_paper_manage_list'))) && !in_array('ROLE_TRAINING_ADMIN'$currentUser['roles']) && !$currentUser->isSuperAdmin()) {
  27.             throw new AccessDeniedException('您没有访问权限,访问被拒绝,如有疑问请联系管理员!');
  28.         }
  29.         return;
  30.     }
  31. }