5 use Drupal\Core\Database\Connection;
10 class BanIpManager implements BanIpManagerInterface {
13 * The database connection used to check the IP against.
15 * @var \Drupal\Core\Database\Connection
17 protected $connection;
20 * Construct the BanSubscriber.
22 * @param \Drupal\Core\Database\Connection $connection
23 * The database connection which will be used to check the IP against.
25 public function __construct(Connection $connection) {
26 $this->connection = $connection;
32 public function isBanned($ip) {
33 return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", [':ip' => $ip])->fetchField();
39 public function findAll() {
40 return $this->connection->query('SELECT * FROM {ban_ip}');
46 public function banIp($ip) {
47 $this->connection->merge('ban_ip')
49 ->fields(['ip' => $ip])
56 public function unbanIp($id) {
57 $this->connection->delete('ban_ip')
58 ->condition('ip', $id)
65 public function findById($ban_id) {
66 return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", [':iid' => $ban_id])->fetchField();