/**
  * @param GetResponseEvent $event GetResponseEvent
  *
  * @return void
  *
  * @throws ServiceUnavailableException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (is_array($this->query)) {
         foreach ($this->query as $key => $pattern) {
             if (!empty($pattern) && preg_match('{' . $pattern . '}', $request->get($key))) {
                 return;
             }
         }
     }
     if (is_array($this->cookie)) {
         foreach ($this->cookie as $key => $pattern) {
             if (!empty($pattern) && preg_match('{' . $pattern . '}', $request->cookies->get($key))) {
                 return;
             }
         }
     }
     if (is_array($this->attributes)) {
         foreach ($this->attributes as $key => $pattern) {
             if (!empty($pattern) && preg_match('{' . $pattern . '}', $request->attributes->get($key))) {
                 return;
             }
         }
     }
     if (null !== $this->path && !empty($this->path) && preg_match('{' . $this->path . '}', rawurldecode($request->getPathInfo()))) {
         return;
     }
     if (null !== $this->host && !empty($this->host) && preg_match('{' . $this->host . '}i', $request->getHost())) {
         return;
     }
     if (count($this->ips) !== 0 && $this->checkIps($request->getClientIp(), $this->ips)) {
         return;
     }
     $route = $request->get('_route');
     if (null !== $this->route && preg_match('{' . $this->route . '}', $route) || true === $this->debug && '_' === $route[0]) {
         return;
     }
     // Get driver class defined in your configuration
     $driver = $this->driverFactory->getDriver();
     if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         $this->handleResponse = true;
         throw new ServiceUnavailableException();
     }
     return;
 }
Exemple #2
0
 /**
  * Whether maintenance mode is on or not
  *
  * @return bool
  */
 public function isOn()
 {
     return $this->factory->getDriver()->decide();
 }