Commit bee18ab1 authored by alexpott's avatar alexpott

Issue #2225685 by ocsilalala: BanIpManager doesn't have interface.

parent 1f9dbcb5
......@@ -12,7 +12,7 @@
/**
* Ban IP manager.
*/
class BanIpManager {
class BanIpManager implements BanIpManagerInterface {
/**
* The database connection used to check the IP against.
......@@ -32,33 +32,21 @@ public function __construct(Connection $connection) {
}
/**
* Returns if this IP address is banned.
*
* @param string $ip
* The IP address to check.
*
* @return bool
* TRUE if the IP address is banned, FALSE otherwise.
* {@inheritdoc}
*/
public function isBanned($ip) {
return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", array(':ip' => $ip))->fetchField();
}
/**
* Finds all banned IP addresses.
*
* @return \Drupal\Core\Database\StatementInterface
* The result of the database query.
* {@inheritdoc}
*/
public function findAll() {
return $this->connection->query('SELECT * FROM {ban_ip}');
}
/**
* Bans an IP address.
*
* @param string $ip
* The IP address to ban.
* {@inheritdoc}
*/
public function banIp($ip) {
$this->connection->insert('ban_ip')
......@@ -67,10 +55,7 @@ public function banIp($ip) {
}
/**
* Unbans an IP address.
*
* @param string $id
* The IP address to unban.
* {@inheritdoc}
*/
public function unbanIp($id) {
$this->connection->delete('ban_ip')
......@@ -79,16 +64,9 @@ public function unbanIp($id) {
}
/**
* Finds a banned IP address by its ID.
*
* @param int $ban_id
* The ID for a banned IP address.
*
* @return string|false
* Either the banned IP address or FALSE if none exist with that ID.
* {@inheritdoc}
*/
public function findById($ban_id) {
return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", array(':iid' => $ban_id))->fetchField();
}
}
<?php
/**
* @file
* Contains \Drupal\ban\BanIpManagerInterface.
*/
namespace Drupal\ban;
/**
* Provides an interface defining a BanIp manager.
*/
interface BanIpManagerInterface {
/**
* Returns if this IP address is banned.
*
* @param string $ip
* The IP address to check.
*
* @return bool
* TRUE if the IP address is banned, FALSE otherwise.
*/
public function isBanned($ip);
/**
* Finds all banned IP addresses.
*
* @return \Drupal\Core\Database\StatementInterface
* The result of the database query.
*/
public function findAll();
/**
* Bans an IP address.
*
* @param string $ip
* The IP address to ban.
*/
public function banIp($ip);
/**
* Unbans an IP address.
*
* @param string $id
* The IP address to unban.
*/
public function unbanIp($id);
/**
* Finds a banned IP address by its ID.
*
* @param int $ban_id
* The ID for a banned IP address.
*
* @return string|false
* Either the banned IP address or FALSE if none exist with that ID.
*/
public function findById($ban_id);
}
......@@ -12,7 +12,7 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\ban\BanIpManager;
use Drupal\ban\BanIpManagerInterface;
use Drupal\Component\Utility\String;
/**
......@@ -23,17 +23,17 @@ class BanSubscriber implements EventSubscriberInterface {
/**
* The manager used to check the IP against.
*
* @var \Drupal\ban\BanIpManager
* @var \Drupal\ban\BanIpManagerInterface
*/
protected $manager;
/**
* Construct the BanSubscriber.
*
* @param \Drupal\ban\BanIpManager $manager
* @param \Drupal\ban\BanIpManagerInterface $manager
* The manager used to check the IP against.
*/
public function __construct(BanIpManager $manager) {
public function __construct(BanIpManagerInterface $manager) {
$this->manager = $manager;
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\ban\Form;
use Drupal\Core\Form\FormBase;
use Drupal\ban\BanIpManager;
use Drupal\ban\BanIpManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -17,16 +17,16 @@
class BanAdmin extends FormBase {
/**
* @var \Drupal\ban\BanIpManager
* @var \Drupal\ban\BanIpManagerInterface
*/
protected $ipManager;
/**
* Constructs a new BanAdmin object.
*
* @param \Drupal\ban\BanIpManager $ip_manager
* @param \Drupal\ban\BanIpManagerInterface $ip_manager
*/
public function __construct(BanIpManager $ip_manager) {
public function __construct(BanIpManagerInterface $ip_manager) {
$this->ipManager = $ip_manager;
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\ban\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\ban\BanIpManager;
use Drupal\ban\BanIpManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
......@@ -27,10 +27,10 @@ class BanDelete extends ConfirmFormBase {
/**
* Constructs a new BanDelete object.
*
* @param \Drupal\ban\BanIpManager $ip_manager
* @param \Drupal\ban\BanIpManagerInterface $ip_manager
* The IP manager.
*/
public function __construct(BanIpManager $ip_manager) {
public function __construct(BanIpManagerInterface $ip_manager) {
$this->ipManager = $ip_manager;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment