class BanIpManager

Ban IP manager.

Hierarchy

Expanded class hierarchy of BanIpManager

1 file declares its use of BanIpManager
BanSubscriber.php in drupal/core/modules/ban/lib/Drupal/ban/EventSubscriber/BanSubscriber.php
Definition of Drupal\ban\EventSubscriber\BanSubscriber.

File

drupal/core/modules/ban/lib/Drupal/ban/BanIpManager.php, line 15
Definition of Drupal\ban\BanIpManager.

Namespace

Drupal\ban
View source
class BanIpManager {

  /**
   * The database connection used to check the IP against.
   *
   * @var Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * Construct the BanSubscriber.
   *
   * @param Drupal\Core\Database\Connection $connection
   *   The database connection which will be used to check the IP against.
   */
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * Returns whether an IP address is blocked.
   *
   * @param string $ip
   *   The IP address to check.
   *
   * @return bool
   *   TRUE if access is denied, FALSE if access is allowed.
   */
  public function isDenied($ip) {
    $denied = $this->connection
      ->query('SELECT 1 FROM {ban_ip} WHERE ip = :ip', array(
      ':ip' => $ip,
    ))
      ->fetchField();
    return (bool) $denied;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BanIpManager::$connection protected property The database connection used to check the IP against.
BanIpManager::isDenied public function Returns whether an IP address is blocked.
BanIpManager::__construct public function Construct the BanSubscriber.