class IPRangesEventSubscriber in IP Ranges 8
Hierarchy
- class \Drupal\ip_ranges\EventSubscriber\IPRangesEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of IPRangesEventSubscriber
1 string reference to 'IPRangesEventSubscriber'
1 service uses IPRangesEventSubscriber
File
- lib/
Drupal/ ip_ranges/ EventSubscriber/ IPRangesEventSubscriber.php, line 12
Namespace
Drupal\ip_ranges\EventSubscriberView source
class IPRangesEventSubscriber implements EventSubscriberInterface {
protected $request;
protected $manager;
public function __construct(Request $request, IPRangesManager $manager) {
$this->request = $request;
$this->manager = $manager;
}
public function onKernelRequest(GetResponseEvent $event) {
if ($this->manager
->ipIsBanned($this->request
->getClientIp())) {
$event
->stopPropagation();
$response = new Response(t('Sorry, @ip has been banned.', array(
'@ip' => $this->request
->getClientIp(),
)), 403);
$event
->setResponse($response);
}
}
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array(
'onKernelRequest',
100,
);
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IPRangesEventSubscriber:: |
protected | property | ||
IPRangesEventSubscriber:: |
protected | property | ||
IPRangesEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
IPRangesEventSubscriber:: |
public | function | ||
IPRangesEventSubscriber:: |
public | function |