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

8.0.x
Alex Pott 2014-03-26 23:16:42 +01:00
parent 1f9dbcb576
commit bee18ab165
5 changed files with 78 additions and 39 deletions

View File

@ -12,7 +12,7 @@ use Drupal\Core\Database\Connection;
/**
* Ban IP manager.
*/
class BanIpManager {
class BanIpManager implements BanIpManagerInterface {
/**
* The database connection used to check the IP against.
@ -32,33 +32,21 @@ class BanIpManager {
}
/**
* 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 @@ class BanIpManager {
}
/**
* 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 @@ class BanIpManager {
}
/**
* 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();
}
}

View File

@ -0,0 +1,61 @@
<?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);
}

View File

@ -12,7 +12,7 @@ use Symfony\Component\HttpKernel\KernelEvents;
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;
}

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
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;
}

View File

@ -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;
}