You are here

public function WebhooksCommands::trigger in Webhooks 8

File

src/Commands/WebhooksCommands.php, line 67

Class

WebhooksCommands
The webhooks Drush commandfile.

Namespace

Drupal\webhooks\Commands

Code

public function trigger($event, $options = [
  'payload' => '',
  'headers' => '',
  'event' => 'default',
  'content_type' => 'application/json',
]) {
  $payload = (array) json_decode($options['payload'], TRUE);
  $headers = (array) json_decode($options['headers'], TRUE);
  $event = $event;
  $content_type = $options['content_type'];
  $webhook = new Webhook($payload, $headers, $event, $content_type);

  // Trigger the webhook for all subscribers.
  $this->webhookService
    ->triggerEvent($webhook, $event);
  $this
    ->logger()
    ->success($this
    ->t('A webhook has been triggered with event @event and payload @payload', [
    '@event' => $event,
    '@payload' => $options['payload'],
  ]));
}