BanIpManager.php in Drupal 10
File
core/modules/ban/src/BanIpManager.php
View source
<?php
namespace Drupal\ban;
use Drupal\Core\Database\Connection;
class BanIpManager implements BanIpManagerInterface {
protected $connection;
public function __construct(Connection $connection) {
$this->connection = $connection;
}
public function isBanned($ip) {
return (bool) $this->connection
->query("SELECT * FROM {ban_ip} WHERE [ip] = :ip", [
':ip' => $ip,
])
->fetchField();
}
public function findAll() {
return $this->connection
->query('SELECT * FROM {ban_ip}');
}
public function banIp($ip) {
$this->connection
->merge('ban_ip')
->key([
'ip' => $ip,
])
->fields([
'ip' => $ip,
])
->execute();
}
public function unbanIp($id) {
$this->connection
->delete('ban_ip')
->condition('ip', $id)
->execute();
}
public function findById($ban_id) {
return $this->connection
->query("SELECT [ip] FROM {ban_ip} WHERE [iid] = :iid", [
':iid' => $ban_id,
])
->fetchField();
}
}