opnform/app/Service/Forms/Webhooks/WebhookHandlerProvider.php

37 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Service\Forms\Webhooks;
use App\Models\Forms\Form;
class WebhookHandlerProvider
{
2024-02-23 10:54:12 +00:00
public const SLACK_PROVIDER = 'slack';
public const DISCORD_PROVIDER = 'discord';
public const SIMPLE_WEBHOOK_PROVIDER = 'webhook';
public const ZAPIER_PROVIDER = 'zapier';
public static function getProvider(Form $form, array $data, string $provider, ?string $webhookUrl = null)
{
switch ($provider) {
case self::SLACK_PROVIDER:
return new SlackHandler($form, $data);
case self::DISCORD_PROVIDER:
return new DiscordHandler($form, $data);
case self::SIMPLE_WEBHOOK_PROVIDER:
return new SimpleWebhookHandler($form, $data);
case self::ZAPIER_PROVIDER:
if (is_null($webhookUrl)) {
throw new \Exception('Zapier webhook url is required');
}
2024-02-23 10:54:12 +00:00
return new ZapierHandler($form, $data, $webhookUrl);
default:
throw new \Exception('Unknown webhook provider');
}
}
}