class BanIpManager

Same name in other branches
  1. 9 core/modules/ban/src/BanIpManager.php \Drupal\ban\BanIpManager
  2. 8.9.x core/modules/ban/src/BanIpManager.php \Drupal\ban\BanIpManager
  3. 11.x core/modules/ban/src/BanIpManager.php \Drupal\ban\BanIpManager

Ban IP manager.

Hierarchy

  • class \Drupal\ban\BanIpManager implements \Drupal\ban\BanIpManagerInterface

Expanded class hierarchy of BanIpManager

1 file declares its use of BanIpManager
IpAddressBlockingTest.php in core/modules/ban/tests/src/Functional/IpAddressBlockingTest.php
1 string reference to 'BanIpManager'
ban.services.yml in core/modules/ban/ban.services.yml
core/modules/ban/ban.services.yml
1 service uses BanIpManager
ban.ip_manager in core/modules/ban/ban.services.yml
Drupal\ban\BanIpManager

File

core/modules/ban/src/BanIpManager.php, line 10

Namespace

Drupal\ban
View source
class BanIpManager implements BanIpManagerInterface {
    
    /**
     * The database connection used to check the IP against.
     *
     * @var \Drupal\Core\Database\Connection
     */
    protected $connection;
    
    /**
     * Constructs a BanIpManager object.
     *
     * @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;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isBanned($ip) {
        return (bool) $this->connection
            ->query("SELECT * FROM {ban_ip} WHERE [ip] = :ip", [
            ':ip' => $ip,
        ])
            ->fetchField();
    }
    
    /**
     * {@inheritdoc}
     */
    public function findAll() {
        return $this->connection
            ->query('SELECT * FROM {ban_ip}');
    }
    
    /**
     * {@inheritdoc}
     */
    public function banIp($ip) {
        $this->connection
            ->merge('ban_ip')
            ->key('ip', $ip)
            ->fields([
            'ip' => $ip,
        ])
            ->execute();
    }
    
    /**
     * {@inheritdoc}
     */
    public function unbanIp($id) {
        $this->connection
            ->delete('ban_ip')
            ->condition('ip', $id)
            ->execute();
    }
    
    /**
     * {@inheritdoc}
     */
    public function findById($ban_id) {
        return $this->connection
            ->query("SELECT [ip] FROM {ban_ip} WHERE [iid] = :iid", [
            ':iid' => $ban_id,
        ])
            ->fetchField();
    }

}

Members

Title Sort descending Modifiers Object type Summary
BanIpManager::$connection protected property The database connection used to check the IP against.
BanIpManager::banIp public function
BanIpManager::findAll public function
BanIpManager::findById public function
BanIpManager::isBanned public function
BanIpManager::unbanIp public function
BanIpManager::__construct public function Constructs a BanIpManager object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.