Fasáda Notifications
Všetko ide cez jednu fasádu, RoundlyConsulting\Notifications\Facades\Notifications, ktorá je skratkou nad singletonom NotificationsManager. Globálny alias neexistuje — od fasády Notification z Laravelu ju delí jedno písmeno — preto ju vždy importujte:
use RoundlyConsulting\Notifications\Facades\Notifications; // no global alias — always import it
// Types — registered once, read for a settings screen
Notifications::define('comment.posted')->category('comments')->window('PT10M')->register();
Notifications::types()->all();
// Send — flat, fluent, or about one subject
Notifications::send('request.awaiting_approval', $request, $approvers, ['reference' => 'PR-9']);
Notifications::type('request.awaiting_approval')->about($request)->to($approvers)->once("request:{$request->id}")->send();
Notifications::for($contract)->send('contract.expiring', Recipients::owner());
// One recipient's inbox and preferences
Notifications::inbox($user)->in($company)->unread()->paginate();
Notifications::preferences($user)->mute('comment.posted');
// One subject's reminders, acknowledgement and revocation
Notifications::for($task)->remind('task.due', Reminder::before('deadline', 'PT1H'), to: $task->assignee);
Notifications::for($contract)->acknowledge('contract.expiring', by: $user);
Notifications::for($request)->revoke($formerMember);
// The time-driven work the scheduler runs
Notifications::sweep();
Notifications::prune();Metódy manažéra
| Metóda | Vracia | Čo robí |
|---|---|---|
send($type, $subject, $recipients, $data = [], $actor = null, $context = null, $idempotencyKey = null) | SendResult | Upozorní príjemcov na jednu udalosť — schránka, e-mail, preferencie, deduplikácia, tiché hodiny, súhrny a prístup pre každého príjemcu. |
sendNotification(SendNotificationData $data) | SendResult | Odoslanie ako DTO — používa ho builder aj samotná akcia. |
type($type) | PendingNotification | Fluentné odoslanie: about, to, by, with, in, once, escalate, send. |
for(Model $subject) | SubjectHandle | Všetko o jednom subjekte: odoslania, pripomienky, potvrdenie, odobratie. |
inbox(Model $recipient) | InboxHandle | Schránka jedného príjemcu — nemenné filtre, čítanie, počty, zmeny. |
preferences(Model $recipient) | PreferencesHandle | Preferencie jedného používateľa: kanály, kategórie, súhrn, tiché hodiny a časové pásmo. |
register(string ...$types) / registerType(NotificationType $type) | void | Zaregistruje druhy podľa triedy alebo inštanciu druhu. |
define(string $key) | TypeBuilder | Druh bez triedy. |
types() | TypesAccessor | all(), categories(), find(), has(), get() — pre obrazovku nastavení. |
reminders() | RemindersAccessor | fireDue(), backfill($type), acknowledge($subject, $type, $by). |
digests() | DigestsAccessor | sendDue(), preview($user). |
deliveries() | DeliveriesAccessor | dispatchDue(). |
interop() | InteropAccessor | map(), suppress(), mapped(), suppressed(). |
inboxMessage(Model $recipient, InboxMessage $message) | ?InboxItem | Zapíše správu kanála inbox z Laravelu do schránky príjemcu. |
sweep(?array $only = null) | SweepReport | Splatné e-maily, súhrny, pripomienky, eskalácie, zastarané prevzatia. |
prune() | PruneReport | Zmaže staré riadky (pozrite Príkazy). |
Notifications::fake() | NotificationsFake | Len na fasáde — fake, ktorý len zaznamenáva (pozrite Testovanie). |
perform() a applyInterop() sú na manažéri verejné, ale interné: perform() je jediný kanál, cez ktorý každý handle, builder, kanál aj trait modelu spúšťa svoju akciu — a háčik, cez ktorý fake zaznamenáva — a applyInterop() volá interop listener. Z kódu aplikácie ich nevolajte.
Notifications::for($subject)
| Metóda | Vracia | Čo robí |
|---|---|---|
send($type, $recipients, $data = [], $actor = null, $context = null, $idempotencyKey = null) | SendResult | Odoslanie o tomto subjekte. |
type($type) | PendingNotification | Fluentné odoslanie s vyplneným subjektom. |
remind($type, ReminderRule $rule, $to, array $data = []) | list<NotificationReminder> | Jednorazová pripomienka. |
reminders() | SubjectReminders | schedule($type, $to), sync(?$type), cancel(?$type), pending(?$type), all(?$type). |
acknowledge(?string $type = null, ?Model $by = null) | int | Potvrdí otvorené pripomienky subjektu a zastaví ich eskalácie. |
revoke(?Model $recipient = null) | int | Odstráni položky príjemcu (alebo všetkých) o subjekte a zruší ich čakajúce e-maily. |
subject() | Model | Subjekt. |
Notifications::inbox($recipient)
Handly sú nemenné — každý filter vráti kópiu:
| Metóda | Vracia | Čo robí |
|---|---|---|
unread() / read() / archived() / withArchived() | InboxHandle | Filtre stavu; predvolene aktívne (nearchivované). |
in(Model|string $context) / withoutContext() / allContexts() | InboxHandle | Jeden kontext (model alebo kľúč ako company:3), len položky bez kontextu, alebo všetky kontexty (predvolené). |
category($category) / type($type) / since(CarbonInterface) | InboxHandle | Zúži podľa kategórie, druhu alebo nedávnej aktivity. |
latest() | InboxHandle | Najnovšia aktivita prvá — predvolené poradie. |
paginate(?int $perPage) / cursorPaginate(?int $perPage) | LengthAwarePaginator / CursorPaginator | Stránky s eager-loadingom aktérov a subjektov; perPage obmedzené na inbox.max_per_page. |
get(?int $limit) / first() | Collection / ?InboxItem | Obmedzený zoznam; najnovšia položka. |
find($item) | InboxItem | Podľa modelu alebo id, len v tejto schránke — inak vyhodí InboxItemNotFoundException. |
unreadCount() / counts() | int / InboxCounts | Počet neprečítaných; neprečítané, celkom a počty pre každý kontext. |
markRead($item) / markUnread($item) | InboxHandle | Stav prečítania; markRead() potvrdí aj pripomienku s acknowledgedOnRead(). |
markAllRead(in: null, category: null) | int | Jeden UPDATE v rámci všetkých filtrov handle; výslovný argument nahradí filter rovnakého druhu. |
archive($item) / unarchive($item) / delete($item) | InboxHandle | Archivuje, vráti z archívu, soft-delete. |
recipient() | Model | Vlastník schránky. |
Notifications::preferences($user)
| Metóda | Vracia | Čo robí |
|---|---|---|
mute($type, ?Channel $channel = null) | PreferencesHandle | Len e-mail — alebo každý stlmiteľný kanál pri zapnutom stlmovaní schránky, alebo jeden kanál. |
unmute($type, ?Channel $channel = null) | PreferencesHandle | Zruší prepis: návrat k predvolenému nastaveniu kategórie a druhu. |
set($type, Channel $channel, bool $enabled) | PreferencesHandle | Výslovné zapnutie alebo vypnutie. |
muteCategory($category, ?Channel) / unmuteCategory($category, ?Channel) | PreferencesHandle | Celá kategória; nepoužitá kategória vyhodí výnimku. |
digest(DigestFrequency $frequency, ?string $time = null) | PreferencesHandle | Off, daily alebo weekly, voliteľne v miestnom čase. |
quietHours(?string $start, ?string $end = null) | PreferencesHandle | Miestny HH:MM; null ich zruší. |
timezone(?string $timezone) | PreferencesHandle | IANA id; null ho zruší. |
update(PreferencesUpdate $update) | PreferencesHandle | Viac zmien naraz, všetky alebo žiadna. |
reset() | PreferencesHandle | Zabudne všetky prepisy druhov a kategórií (súhrn, tiché hodiny a časové pásmo zostanú). |
matrix() / overview() | list<PreferenceRow> / PreferencesOverview | Dáta pre obrazovku nastavení, preložené. |
enabled($type, Channel) / muted($type) | bool | Výsledný stav kanála; či je e-mail vypnutý. |
digestPreference() / quietHoursPreference() / resolvedTimezone() | DigestPreferenceData / ?QuietHours / string | Výsledný súhrn, tiché hodiny a časové pásmo. |
user() | Model | Používateľ. |
Buildery, DTO a enumy
- Buildery: PendingNotification (about, to, by, with, in, once, escalate, data, send), TypeBuilder (pozrite Druhy notifikácií), pravidlá pripomienok Reminder, ReminderRule a EscalationRule a Context (of, key).
- DTO (final readonly): SendNotificationData, SendResult, RecipientOutcome, TypeDefinition, CategoryDefinition, PreferenceRow, ChannelPreference, PreferencesOverview, PreferencesUpdate, DigestPreferenceData, QuietHours, InboxCounts, ContextCount, ContextReference, ReminderReference, SweepReport, PruneReport, FiredReminders.
- Enumy: Channel (inbox, mail), Priority (low, normal, urgent), DigestFrequency (off, daily, weekly), MailStrategy (leading, trailing), DeliveryStatus, DigestRunStatus, ReminderStatus (pending, firing, sent, cancelled, skipped), ReminderKind, InboxOutcome, MailOutcome, CancelReason a NotificationOperation. Tie, ktoré vidí používateľ, majú preložené popisy.
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 kryptomienOdoslaní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.