You are here

class RequestSubscriber in Lightning API 8

Same name and namespace in other branches
  1. 8.4 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
  2. 8.2 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
  3. 8.3 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber

Hierarchy

Expanded class hierarchy of RequestSubscriber

1 string reference to 'RequestSubscriber'
lightning_api.services.yml in ./lightning_api.services.yml
lightning_api.services.yml
1 service uses RequestSubscriber
lightning_api.request_subscriber in ./lightning_api.services.yml
\Drupal\lightning_api\RequestSubscriber

File

src/RequestSubscriber.php, line 12

Namespace

Drupal\lightning_api
View source
class RequestSubscriber implements EventSubscriberInterface {
  use StringTranslationTrait;

  /**
   * The current route match service.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * The OAuth key service.
   *
   * @var \Drupal\lightning_api\OAuthKey
   */
  protected $key;

  /**
   * RequestSubscriber constructor.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match service.
   * @param \Drupal\lightning_api\OAuthKey $key
   *   The OAuth keys service.
   */
  public function __construct(RouteMatchInterface $route_match, OAuthKey $key, TranslationInterface $translation) {
    $this->routeMatch = $route_match;
    $this->key = $key;
    $this
      ->setStringTranslation($translation);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::REQUEST => 'onRequest',
    ];
  }
  public function onRequest() {
    if ($this->routeMatch
      ->getRouteName() == 'oauth2_token.settings' && $this->key
      ->exists() == FALSE) {
      $url = Url::fromRoute('lightning_api.generate_keys');
      drupal_set_message($this
        ->t('You may wish to <a href=":generate_keys">generate a key pair</a> for OAuth authentication.', [
        ':generate_keys' => $url
          ->toString(),
      ]), 'warning');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestSubscriber::$key protected property The OAuth key service.
RequestSubscriber::$routeMatch protected property The current route match service.
RequestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RequestSubscriber::onRequest public function
RequestSubscriber::__construct public function RequestSubscriber constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.