You are here

class GeolocateUserSubscriber in Smart IP 8.4

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/GeolocateUserSubscriber.php \Drupal\smart_ip\EventSubscriber\GeolocateUserSubscriber
  2. 8.3 src/EventSubscriber/GeolocateUserSubscriber.php \Drupal\smart_ip\EventSubscriber\GeolocateUserSubscriber

Allows Smart IP to act on HTTP request event.

@package Drupal\smart_ip\EventSubscriber

Hierarchy

  • class \Drupal\smart_ip\EventSubscriber\GeolocateUserSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of GeolocateUserSubscriber

1 string reference to 'GeolocateUserSubscriber'
smart_ip.services.yml in ./smart_ip.services.yml
smart_ip.services.yml
1 service uses GeolocateUserSubscriber
smart_ip.geolocate_user_subscriber in ./smart_ip.services.yml
Drupal\smart_ip\EventSubscriber\GeolocateUserSubscriber

File

src/EventSubscriber/GeolocateUserSubscriber.php, line 20
Contains \Drupal\smart_ip\EventSubscriber\GeolocateUserSubscriber.

Namespace

Drupal\smart_ip\EventSubscriber
View source
class GeolocateUserSubscriber implements EventSubscriberInterface {

  /**
   * Initiate user geolocation.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The response event, which contains the current request.
   */
  public function geolocateUser(GetResponseEvent $event) {

    // Check to see if the page is one of those allowed for geolocation.
    if (!SmartIp::checkAllowedPage()) {

      // This page is not on the list to acquire/update user's geolocation.
      return;
    }

    // Save a database hit.
    SmartIp::updateUserLocation();
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = [
      'geolocateUser',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GeolocateUserSubscriber::geolocateUser public function Initiate user geolocation.
GeolocateUserSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.