1 | <?php |
||
2 | |||
3 | namespace App\Event; |
||
4 | |||
5 | use App\Controller\AuthenticatedInterface; |
||
6 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
||
7 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
8 | use Symfony\Component\HttpKernel\Event\FilterControllerEvent; |
||
9 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
||
10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
||
11 | use Symfony\Component\HttpKernel\HttpKernel; |
||
12 | use Symfony\Component\HttpKernel\KernelEvents; |
||
13 | |||
14 | class StudentSubscriber implements EventSubscriberInterface |
||
15 | { |
||
16 | |||
17 | |||
18 | public function __construct(ContainerInterface $container) |
||
0 ignored issues
–
show
|
|||
19 | { |
||
20 | |||
21 | } |
||
22 | |||
23 | public function onKernelController(FilterControllerEvent $event) |
||
24 | { |
||
25 | $controller = $event->getController(); |
||
26 | |||
27 | /* |
||
28 | * $controller passed can be either a class or a Closure. |
||
29 | * This is not usual in Symfony but it may happen. |
||
30 | * If it is a class, it comes in array format |
||
31 | */ |
||
32 | if (!is_array($controller)) { |
||
33 | return; |
||
34 | } |
||
35 | |||
36 | if ($controller[0] instanceof AuthenticatedInterface) { |
||
37 | if (isset($_SESSION['phpCAS']['user'])) { |
||
38 | throw new AccessDeniedHttpException('Access forbidden.'); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | public function onKernelRequest(GetResponseEvent $event) |
||
44 | { |
||
45 | if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | |||
50 | public static function getSubscribedEvents() |
||
51 | { |
||
52 | return [ KernelEvents::CONTROLLER => 'onKernelController' ]; |
||
53 | } |
||
54 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.