Ban subscriber for controller requests.
Expanded class hierarchy of BanSubscriber
class BanSubscriber implements EventSubscriberInterface {
/**
* The manager used to check the IP against.
*
* @var Drupal\ban\BanIpManager
*/
protected $manager;
/**
* Construct the BanSubscriber.
*
* @param Drupal\ban\BanIpManager $manager
* The manager used to check the IP against.
*/
public function __construct(BanIpManager $manager) {
$this->manager = $manager;
}
/**
* Response with 403 if the visitor's IP adress is banned.
*
* @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/
public function onKernelRequestBannedIpCheck(GetResponseEvent $event) {
// @todo convert this to Request::getClientIP().
$ip = ip_address();
if ($this->manager
->isDenied($ip)) {
$response = new Response('Sorry, ' . check_plain($ip) . ' has been banned.', 403);
$event
->setResponse($response);
}
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array(
'onKernelRequestBannedIpCheck',
40,
);
return $events;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BanSubscriber:: |
protected | property | The manager used to check the IP against. | |
BanSubscriber:: |
static | function |
Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface:: |
|
BanSubscriber:: |
public | function | Response with 403 if the visitor's IP adress is banned. | |
BanSubscriber:: |
public | function | Construct the BanSubscriber. |