NovinkaZverejnili sme 50+ Laravel balíkov ako open source
Custom AI apps, agents and automation — Roundly ConsultingRoundly
Všetky balíky

Fasáda je odporúčaná predvoľba, nie jediná cesta. Každá operácia je akcia, manažér sprístupňuje každú z nich a fasáda je skratka nad manažérom — všetky tri spúšťajú rovnaký kód. Manažér je RoundlyConsulting\Notifications\NotificationsManager, koreň fasády, zaregistrovaný v kontajneri ako singleton:

use RoundlyConsulting\Notifications\Actions\Sending\SendNotificationAction;
use RoundlyConsulting\Notifications\DataTransferObjects\SendNotificationData;
use RoundlyConsulting\Notifications\Facades\Notifications;
use RoundlyConsulting\Notifications\NotificationsManager;
use RoundlyConsulting\Notifications\Recipients;

// 1. Facade
Notifications::send('request.awaiting_approval', $request, $approvers, ['reference' => $request->reference]);

// 2. Dependency injection — the same API, no facade
app(NotificationsManager::class)->send('request.awaiting_approval', $request, $approvers);

// 3. The raw action
app(SendNotificationAction::class)->execute(new SendNotificationData(
    type: 'request.awaiting_approval',
    subject: $request,
    recipients: Recipients::users(...$approvers),
));

Injektovanie manažéra

use Illuminate\Http\RedirectResponse;
use RoundlyConsulting\Notifications\NotificationsManager;
use RoundlyConsulting\Notifications\Recipients;

final class SubmitPurchaseRequestController
{
    public function __construct(private NotificationsManager $notifications) {}

    public function __invoke(PurchaseRequest $request): RedirectResponse
    {
        $request->submit();

        $this->notifications->type('request.awaiting_approval')
            ->about($request)
            ->to(Recipients::role($request->company, 'approver'))
            ->by($request->author)
            ->once("request-submitted:{$request->id}")
            ->send();

        return to_route('requests.show', $request);
    }
}

Manažér zámerne nie je final: fake ho rozširuje, takže kód, ktorý injektuje NotificationsManager, prejde typovou kontrolou aj pod Notifications::fake().

Volanie akcie

use RoundlyConsulting\Notifications\Actions\Inbox\MarkInboxItemReadAction;
use RoundlyConsulting\Notifications\Actions\Preferences\UpdatePreferencesAction;
use RoundlyConsulting\Notifications\Actions\Reminders\AcknowledgeAction;

// Notifications::inbox($user)->markRead($item)  ≡
app(MarkInboxItemReadAction::class)->execute($user, $item);

// Notifications::preferences($user)->update($update)  ≡
app(UpdatePreferencesAction::class)->execute($user, $update);

// Notifications::for($contract)->acknowledge('contract.expiring', by: $user)  ≡
app(AcknowledgeAction::class)->execute($contract, 'contract.expiring', $user);

Metóda fasády → akcia

Menné priestory sú relatívne k RoundlyConsulting\Notifications\Actions:

Akciaexecute(…)VraciaCesta cez fasádu
Sending\SendNotificationActionexecute(SendNotificationData)SendResultsend() · sendNotification() · type()->send() · for()->send()
Inbox\MarkInboxItemReadActionexecute($recipient, $item)InboxIteminbox()->markRead()
Inbox\MarkInboxItemUnreadActionexecute($recipient, $item)InboxIteminbox()->markUnread()
Inbox\MarkAllInboxItemsReadActionexecute($recipient, $in, $category, $type, $withoutContext, $since)intinbox()->markAllRead()
Inbox\ArchiveInboxItemAction · UnarchiveInboxItemActionexecute($recipient, $item)InboxIteminbox()->archive() · unarchive()
Inbox\DeleteInboxItemActionexecute($recipient, $item)voidinbox()->delete()
Inbox\RevokeNotificationsActionexecute($subject, ?$recipient)intfor()->revoke()
Inbox\RecordInboxMessageActionexecute($recipient, InboxMessage)?InboxIteminboxMessage() · the inbox channel
Preferences\SetChannelPreferenceActionexecute($user, $type, list<Channel>, ?bool)voidpreferences()->mute() · unmute() · set()
Preferences\SetCategoryPreferenceActionexecute($user, $category, list<Channel>, ?bool)voidpreferences()->muteCategory() · unmuteCategory()
Preferences\ResetPreferencesActionexecute($user)voidpreferences()->reset()
Preferences\SetDigestPreferenceActionexecute($user, DigestPreferenceData)voidpreferences()->digest()
Preferences\SetQuietHoursActionexecute($user, ?QuietHours)voidpreferences()->quietHours()
Preferences\SetNotificationTimezoneActionexecute($user, ?string)voidpreferences()->timezone()
Preferences\UpdatePreferencesActionexecute($user, PreferencesUpdate)voidpreferences()->update() · PATCH /preferences
Delivery\DispatchDueDeliveriesActionexecute()intdeliveries()->dispatchDue()
Digests\SendDueDigestsAction · PreviewDigestActionexecute() · execute($user)int · ?MailMessagedigests()->sendDue() · preview()
Reminders\SyncRemindersActionexecute($subject, ?$type)intfor()->reminders()->sync()
Reminders\ScheduleRemindersActionexecute($subject, $type, RecipientSpec)list<NotificationReminder>for()->reminders()->schedule()
Reminders\RemindActionexecute($subject, $type, ReminderRule, RecipientSpec, $data)list<NotificationReminder>for()->remind()
Reminders\CancelRemindersActionexecute($subject, ?$type, CancelReason)intfor()->reminders()->cancel()
Reminders\AcknowledgeActionexecute($subject, ?$type, ?$by)intfor()->acknowledge() · reminders()->acknowledge()
Reminders\FireDueRemindersAction · BackfillRemindersActionexecute() · execute($type)FiredReminders · intreminders()->fireDue() · backfill()
Maintenance\SweepAction · PruneNotificationsActionexecute(?$only) · execute()SweepReport · PruneReportsweep() · prune()
  • Každé meniace volanie — z fasády, injektovaného manažéra, handle, fluentného buildera, traitu modelu alebo kanála inbox — prechádza manažérom, ktorý akciu vytvorí z kontajnera, takže vlastné naviazanie akcie v kontajneri platí všade.
  • Notifications::fake() vymení manažéra aj v kontajneri, takže fake platí aj pre injektovaný NotificationsManager. Priame volanie akcie sa nezaznamená.
  • Interné stavebné bloky — ResolveRecipientsAction, DeliverToRecipientAction, RecordInboxItemAction, QueueMailDeliveryAction, RecomputeDeferredDeliveriesAction, DeliverMailAction, ExpireStaleClaimsAction, SendDigestAction, FireReminderAction, FireEscalationAction, ApplyInteropRulesAction a ReleaseHeldInteropMailAction — nie sú určené pre kód aplikácie.

Prejavte lásku k open source

Tento balík je zadarmo pod licenciou MIT. Ak vám šetrí čas, jednorazový príspevok alebo členstvo na Patreone nám pomôže ho ďalej udržiavať, testovať a dokumentovať.

Ďalšie spôsoby podpory vrátane kryptomien

Odoslaním daru súhlasíte s našimi podmienkami prijímania darov.

Chcete to zabudovať do svojho produktu?

Naše balíky integrujeme do zákazkových Laravel a AI riešení. Napíšte nám, na čom pracujete, a ozveme sa do 48 hodín.