class RequestSubscriber in Lightning API 8.3
Same name and namespace in other branches
- 8.4 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
- 8 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
- 8.2 src/RequestSubscriber.php \Drupal\lightning_api\RequestSubscriber
Reacts to incoming HTTP requests.
Hierarchy
- class \Drupal\lightning_api\RequestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses MessengerTrait, StringTranslationTrait
Expanded class hierarchy of RequestSubscriber
1 string reference to 'RequestSubscriber'
1 service uses RequestSubscriber
File
- src/
RequestSubscriber.php, line 16
Namespace
Drupal\lightning_apiView source
class RequestSubscriber implements EventSubscriberInterface {
use MessengerTrait;
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.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation 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',
];
}
/**
* Reacts to an incoming request.
*/
public function onRequest() {
if ($this->routeMatch
->getRouteName() == 'oauth2_token.settings' && $this->key
->exists() == FALSE) {
$warning = $this
->t('You may wish to <a href=":generate_keys">generate a key pair</a> for OAuth authentication.', [
':generate_keys' => Url::fromRoute('lightning_api.generate_keys')
->toString(),
]);
$this
->messenger()
->addWarning($warning);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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 | Reacts to an incoming request. | |
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. |