Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
9 / 9 |
|
12.50% |
1 / 8 |
|
11.11% |
1 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
0.00% |
0 / 1 |
| KernelRequestListener | |
100.00% |
9 / 9 |
|
12.50% |
1 / 8 |
|
11.11% |
1 / 9 |
|
100.00% |
2 / 2 |
22.56 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onKernelRequest | |
100.00% |
5 / 5 |
|
0.00% |
0 / 7 |
|
0.00% |
0 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Listener; |
| 4 | |
| 5 | use App\Application; |
| 6 | use App\Parameter; |
| 7 | use App\Security\Role; |
| 8 | use Symfony\Bundle\SecurityBundle\Security; |
| 9 | use Symfony\Component\EventDispatcher\Attribute\AsEventListener; |
| 10 | use Symfony\Component\HttpKernel\Event\RequestEvent; |
| 11 | use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; |
| 12 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
| 13 | use Twig\Environment; |
| 14 | |
| 15 | class KernelRequestListener |
| 16 | { |
| 17 | /** @var UrlGeneratorInterface */ |
| 18 | protected $urlGenerator; |
| 19 | |
| 20 | protected Parameter $parameter; |
| 21 | |
| 22 | protected Application $application; |
| 23 | |
| 24 | protected Security $security; |
| 25 | protected Environment $twig; |
| 26 | |
| 27 | public function __construct( |
| 28 | Parameter $parameter, |
| 29 | Application $application, |
| 30 | Security $security, |
| 31 | Environment $twig, |
| 32 | ) { |
| 33 | $this->parameter = $parameter; |
| 34 | $this->application = $application; |
| 35 | $this->security = $security; |
| 36 | $this->twig = $twig; |
| 37 | } |
| 38 | |
| 39 | #[AsEventListener()] |
| 40 | public function onKernelRequest(RequestEvent $event): void |
| 41 | { |
| 42 | $request = $event->getRequest(); |
| 43 | // test le mode maintenance doit ĂȘtre affichĂ© |
| 44 | if ( |
| 45 | $this->parameter->modeMaintenance |
| 46 | && ('saml_login' != $request->attributes->get('_route')) |
| 47 | && !$this->security->isGranted(Role::ADMINISTRATEUR) |
| 48 | ) { |
| 49 | throw new ServiceUnavailableHttpException(); |
| 50 | } |
| 51 | } |
| 52 | } |