You are here

class WebhooksTestSubscriber in Webhooks 8

Webhooks Test event subscriber.

Hierarchy

  • class \Drupal\webhooks_test\EventSubscriber\WebhooksTestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of WebhooksTestSubscriber

1 string reference to 'WebhooksTestSubscriber'
webhooks_test.services.yml in tests/modules/webhooks_test/webhooks_test.services.yml
tests/modules/webhooks_test/webhooks_test.services.yml
1 service uses WebhooksTestSubscriber
webhooks_test.event_subscriber in tests/modules/webhooks_test/webhooks_test.services.yml
Drupal\webhooks_test\EventSubscriber\WebhooksTestSubscriber

File

tests/modules/webhooks_test/src/EventSubscriber/WebhooksTestSubscriber.php, line 15

Namespace

Drupal\webhooks_test\EventSubscriber
View source
class WebhooksTestSubscriber implements EventSubscriberInterface {

  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * The state store.
   *
   * @var \Drupal\Core\State\State
   */
  protected $state;

  /**
   * Constructs event subscriber.
   *
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger.
   * @param \Drupal\Core\State\State $state
   *   The object State.
   */
  public function __construct(MessengerInterface $messenger, State $state) {
    $this->messenger = $messenger;
    $this->state = $state;
  }

  /**
   * Webhook send event handler.
   *
   * @param \Drupal\webhooks\Event\SendEvent $event
   *   Response event.
   */
  public function onWebhookSend(SendEvent $event) {
    $this->state
      ->set(__FUNCTION__, TRUE);
    $webhook = $event
      ->getWebhook();
    $webhook_config = $event
      ->getWebhookConfig();
    $this->state
      ->set(__FUNCTION__ . '_webhook', $webhook);
    $this->state
      ->set(__FUNCTION__ . '_webhook_config', $webhook_config);
    $this->messenger
      ->addStatus(print_r($webhook_config, TRUE));
    $this->messenger
      ->addStatus(print_r($webhook, TRUE));
  }

  /**
   * Webhook receive event handler.
   *
   * @param \Drupal\webhooks\Event\ReceiveEvent $event
   *   Response event.
   */
  public function onWebhookReceive(ReceiveEvent $event) {
    $this->state
      ->set(__FUNCTION__, TRUE);
    $webhook = $event
      ->getWebhook();
    $webhook_config = $event
      ->getWebhookConfig();
    $this->state
      ->set(__FUNCTION__ . '_webhook', $webhook);
    $this->state
      ->set(__FUNCTION__ . '_webhook_config', $webhook_config);
    $this->messenger
      ->addStatus(print_r($webhook_config, TRUE));
    $this->messenger
      ->addStatus(print_r($webhook, TRUE));
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      WebhookEvents::SEND => [
        'onWebhookSend',
      ],
      WebhookEvents::RECEIVE => [
        'onWebhookReceive',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebhooksTestSubscriber::$messenger protected property The messenger.
WebhooksTestSubscriber::$state protected property The state store.
WebhooksTestSubscriber::getSubscribedEvents public static function
WebhooksTestSubscriber::onWebhookReceive public function Webhook receive event handler.
WebhooksTestSubscriber::onWebhookSend public function Webhook send event handler.
WebhooksTestSubscriber::__construct public function Constructs event subscriber.