Mercurial > hg > isophonics-drupal-site
comparison core/modules/ban/src/BanIpManager.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\ban; | |
4 | |
5 use Drupal\Core\Database\Connection; | |
6 | |
7 /** | |
8 * Ban IP manager. | |
9 */ | |
10 class BanIpManager implements BanIpManagerInterface { | |
11 | |
12 /** | |
13 * The database connection used to check the IP against. | |
14 * | |
15 * @var \Drupal\Core\Database\Connection | |
16 */ | |
17 protected $connection; | |
18 | |
19 /** | |
20 * Construct the BanSubscriber. | |
21 * | |
22 * @param \Drupal\Core\Database\Connection $connection | |
23 * The database connection which will be used to check the IP against. | |
24 */ | |
25 public function __construct(Connection $connection) { | |
26 $this->connection = $connection; | |
27 } | |
28 | |
29 /** | |
30 * {@inheritdoc} | |
31 */ | |
32 public function isBanned($ip) { | |
33 return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", [':ip' => $ip])->fetchField(); | |
34 } | |
35 | |
36 /** | |
37 * {@inheritdoc} | |
38 */ | |
39 public function findAll() { | |
40 return $this->connection->query('SELECT * FROM {ban_ip}'); | |
41 } | |
42 | |
43 /** | |
44 * {@inheritdoc} | |
45 */ | |
46 public function banIp($ip) { | |
47 $this->connection->merge('ban_ip') | |
48 ->key(['ip' => $ip]) | |
49 ->fields(['ip' => $ip]) | |
50 ->execute(); | |
51 } | |
52 | |
53 /** | |
54 * {@inheritdoc} | |
55 */ | |
56 public function unbanIp($id) { | |
57 $this->connection->delete('ban_ip') | |
58 ->condition('ip', $id) | |
59 ->execute(); | |
60 } | |
61 | |
62 /** | |
63 * {@inheritdoc} | |
64 */ | |
65 public function findById($ban_id) { | |
66 return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", [':iid' => $ban_id])->fetchField(); | |
67 } | |
68 | |
69 } |