You are here

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'
ip_ranges.services.yml in ./ip_ranges.services.yml
ip_ranges.services.yml
1 service uses IPRangesEventSubscriber
ip_ranges.subscriber in ./ip_ranges.services.yml
Drupal\ip_ranges\EventSubscriber\IPRangesEventSubscriber

File

lib/Drupal/ip_ranges/EventSubscriber/IPRangesEventSubscriber.php, line 12

Namespace

Drupal\ip_ranges\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
IPRangesEventSubscriber::$manager protected property
IPRangesEventSubscriber::$request protected property
IPRangesEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
IPRangesEventSubscriber::onKernelRequest public function
IPRangesEventSubscriber::__construct public function