class RequestSubscriber in Lightning API 8
Same name and namespace in other branches
- 8.4 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
- 8.2 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
- 8.3 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
Hierarchy
- class \Drupal\lightning_api\RequestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of RequestSubscriber
1 string reference to 'RequestSubscriber'
1 service uses RequestSubscriber
File
- src/
RequestSubscriber.php, line 12
Namespace
Drupal\lightning_apiView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RequestSubscriber:: |
protected | property | The OAuth key service. | |
RequestSubscriber:: |
protected | property | The current route match service. | |
RequestSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RequestSubscriber:: |
public | function | ||
RequestSubscriber:: |
public | function | RequestSubscriber constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |