
* update composer.lock * run pint * fix phpstan * update migrations (sqlite `dropForeign`) * fix migrations * Reset these back for now * Alphabetize the rules * run `php artisan filament:upgrade` --------- Co-authored-by: Lance Pioch <git@lance.sh>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Jobs\ProcessWebhook;
|
|
use App\Models\WebhookConfiguration;
|
|
|
|
class DispatchWebhooks
|
|
{
|
|
public function handle(string $eventName, array $data): void
|
|
{
|
|
if (!$this->eventIsWatched($eventName)) {
|
|
return;
|
|
}
|
|
|
|
$matchingHooks = cache()->rememberForever("webhooks.$eventName", function () use ($eventName) {
|
|
return WebhookConfiguration::query()->whereJsonContains('events', $eventName)->get();
|
|
});
|
|
|
|
/** @var WebhookConfiguration $webhookConfig */
|
|
foreach ($matchingHooks as $webhookConfig) {
|
|
if (in_array($eventName, $webhookConfig->events)) {
|
|
ProcessWebhook::dispatch($webhookConfig, $eventName, $data);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function eventIsWatched(string $eventName): bool
|
|
{
|
|
$watchedEvents = cache()->rememberForever('watchedWebhooks', function () {
|
|
return WebhookConfiguration::pluck('events')
|
|
->flatten()
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
});
|
|
|
|
return in_array($eventName, $watchedEvents);
|
|
}
|
|
}
|