You are here

public function RestrictIpService::testForBlock in Restrict IP 8

Same name and namespace in other branches
  1. 8.2 src/Service/RestrictIpService.php \Drupal\restrict_ip\Service\RestrictIpService::testForBlock()
  2. 3.x src/Service/RestrictIpService.php \Drupal\restrict_ip\Service\RestrictIpService::testForBlock()

*

Overrides RestrictIpServiceInterface::testForBlock

File

src/Service/RestrictIpService.php, line 106

Class

RestrictIpService

Namespace

Drupal\restrict_ip\Service

Code

public function testForBlock($runInCli = FALSE) {
  $this->blocked = FALSE;
  if ($this->config
    ->get('enable')) {
    $this->blocked = TRUE;

    // We don't want to check IP on CLI (likely drush) requests
    // unless explicitly declared to check by the $runInCli argument
    if (PHP_SAPI != 'cli' || $runInCli) {
      $access_denied = TRUE;
      if ($this
        ->allowAccessWhitelistedPath()) {
        $access_denied = FALSE;
      }
      elseif ($this
        ->allowAccessBlacklistedPath()) {
        $access_denied = FALSE;
      }
      elseif ($this
        ->allowAccessWhitelistedIp()) {
        $access_denied = FALSE;
      }

      // If the user has been denied access
      if ($access_denied) {
        if (PHP_SAPI != 'cli') {
          $_SESSION['restrict_ip'] = TRUE;
        }
      }
      else {
        $this->blocked = FALSE;
      }
    }
  }
}