Skip to content

Commit 5879f22

Browse files
committed
fix #8
1 parent 0bd2f23 commit 5879f22

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

EventListener/MaintenanceListener.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Artgris\MaintenanceBundle\EventListener;
55

66

7+
use Symfony\Component\HttpFoundation\IpUtils;
78
use Symfony\Component\HttpFoundation\Response;
89
use Symfony\Component\HttpKernel\Event\RequestEvent;
910
use Symfony\Component\HttpKernel\KernelInterface;
@@ -55,12 +56,18 @@ public function __construct(array $maintenance, KernelInterface $kernel, Environ
5556

5657
public function onKernelRequest(RequestEvent $event)
5758
{
58-
/**
59-
* Conditions : Maintenance enable, not in dev/test mode, not in enable Ips
60-
*/
61-
if ($this->enable && !in_array($this->kernel->getEnvironment(), ['dev']) && !in_array(@$_SERVER['REMOTE_ADDR'], $this->ips)) {
59+
60+
if (!$event->isMasterRequest()) {
61+
return;
62+
}
63+
64+
$request = $event->getRequest();
65+
66+
if ($this->enable && $this->kernel->getEnvironment() != 'dev' && !IpUtils::checkIp($request->getClientIp(), $this->ips)) {
6267
$content = $this->twig_Environment->render('@ArtgrisMaintenance/maintenance.html.twig');
6368
$event->setResponse(new Response($content, $this->response));
6469
}
6570
}
71+
72+
6673
}

0 commit comments

Comments
 (0)