46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Notifications;
|
|
|
|
use App\Models\NotificationAction;
|
|
use App\Models\Project;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class StoreProjectNotificationAction
|
|
{
|
|
/**
|
|
* @param array{
|
|
* channel: mixed,
|
|
* channel_configuration?: array<string, mixed>|null,
|
|
* delivery_url: string,
|
|
* enabled: bool,
|
|
* event_type: mixed,
|
|
* message_template?: string|null,
|
|
* name: string
|
|
* } $validated
|
|
*/
|
|
public function handle(Project $project, array $validated): NotificationAction
|
|
{
|
|
return $project->notificationActions()->create([
|
|
'channel' => Arr::get($validated, 'channel'),
|
|
'channel_configuration' => Arr::get($validated, 'channel_configuration') ?? [],
|
|
'delivery_url' => trim((string) Arr::get($validated, 'delivery_url')),
|
|
'enabled' => (bool) Arr::get($validated, 'enabled'),
|
|
'event_type' => Arr::get($validated, 'event_type'),
|
|
'message_template' => $this->normalizeMessageTemplate(Arr::get($validated, 'message_template')),
|
|
'name' => trim((string) Arr::get($validated, 'name')),
|
|
]);
|
|
}
|
|
|
|
private function normalizeMessageTemplate(mixed $messageTemplate): ?string
|
|
{
|
|
if (! is_string($messageTemplate)) {
|
|
return null;
|
|
}
|
|
|
|
$messageTemplate = trim($messageTemplate);
|
|
|
|
return $messageTemplate === '' ? null : $messageTemplate;
|
|
}
|
|
}
|