class Notifications

Utilities that support console commands related to Notifications:

  • Resolving notifiables and channels from CLI options
  • Building per-send payloads/overrides
  • Scaffolding notification classes and the notifications migration
  • Performing dry-runs and actual sends via a notifiable

Constants

NOTIFICATION_NAMESPACE

NOTIFICATION_PATH

Methods

static array
buildPayload(InputInterface $input, array $overrides)

Build the per-send payload for the test command.

static array
channelOptions(InputInterface $input)

Resolve the --channels option into a normalized list of channels.

static bool
dryRun(object|string $notifiable, Notification $notification, array $payload, array|null $channels)

Perform a dry-run (no delivery). Prints the intended action and payload.

static int
makeNotification(array|null $channels, string $notificationName)

Generate a new notification class file into {self::NOTIFICATION_PATH}.

static string
migrationTemplate(string $fileName)

Template for the notifications migration class file.

static string
notificationClass(string $notificationName)

Build a fully-qualified notification class name.

static bool
notificationClassExists(string $className)

Determine if a notification class exists.

static int
notificationsMigration()

Create a new notifications migration file on disk.

static object|string
resolveNotifiable(InputInterface $input)

Resolve a notifiable instance (or a sentinel string) from CLI input.

static array
resolveOverridesFromWith(InputInterface $input)

Parse overrides from the --with option (key:value,key2:value2).

static int
prune(int $days)

Prune old notifications using the model layer.

static array|null
resolveChannelsOverride(InputInterface $input)

Resolve a channels override list from CLI input.

static void
sendViaNotifiable(object|string $notifiable, Notification $notification, array $payload, array|null $channels)

Deliver a notification via a notifiable (or simulate if notifiable is not an object).

Details

at line 40
static array buildPayload(InputInterface $input, array $overrides)

Build the per-send payload for the test command.

Default fields:

  • level: "info"
  • tags: ["cli","test"]
  • dry_run: boolean (from --dry-run)

Parameters

InputInterface $input

Console input (expects option "dry-run").

array $overrides

Arbitrary key/value overrides (takes precedence).

Return Value

array

Merged payload passed to channels.

at line 63
static array channelOptions(InputInterface $input)

Resolve the --channels option into a normalized list of channels.

Behavior:

  • If the option is omitted or empty, returns ALL enum channel values (use {\Console\Helpers\resolveChannelsOverride()} if you prefer NULL to defer to via()).
  • Accepts a comma-separated list, whitespace tolerated.
  • Accepts the special token "all" to mean all channel enum values.
  • Validates unknown names and deduplicates while preserving order.

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

array

Normalized channel names (e.g., ['database','log']).

Exceptions

InvalidArgumentException

at line 101
static bool dryRun(object|string $notifiable, Notification $notification, array $payload, array|null $channels)

Perform a dry-run (no delivery). Prints the intended action and payload.

Parameters

object|string $notifiable

Notifiable instance or a sentinel string (e.g., "dummy").

Notification $notification

The notification instance.

array $payload

Payload merged from defaults and overrides.

array|null $channels

Channels override (NULL → will use via()).

Return Value

bool

TRUE if dry-run occurred; FALSE otherwise.

at line 155
static int makeNotification(array|null $channels, string $notificationName)

Generate a new notification class file into {self::NOTIFICATION_PATH}.

The generated class includes channel methods (toX) for the provided list, plus a via() that references those channels. If $channels is NULL or empty, all enum channel values are used.

Parameters

array|null $channels

Channel names to scaffold (e.g., ['database','log']).

string $notificationName

Class name (without namespace).

Return Value

int

A Tools::writeFile status code.

at line 179
static string migrationTemplate(string $fileName)

Template for the notifications migration class file.

Parameters

string $fileName

The base filename/classname to use.

Return Value

string

The complete PHP contents of the migration.

at line 229
static string notificationClass(string $notificationName)

Build a fully-qualified notification class name.

Parameters

string $notificationName

Short class name or FQCN (leading backslash allowed).

Return Value

string

FQCN of the notification.

at line 241
static bool notificationClassExists(string $className)

Determine if a notification class exists.

Parameters

string $className

FQCN to check.

Return Value

bool

TRUE if loadable; FALSE otherwise.

at line 250
static int notificationsMigration()

Create a new notifications migration file on disk.

Return Value

int

A Tools::writeFile status code.

at line 303
static object|string resolveNotifiable(InputInterface $input)

Resolve a notifiable instance (or a sentinel string) from CLI input.

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

object|string

A model instance or "dummy" if none found/provided.

at line 318
static array resolveOverridesFromWith(InputInterface $input)

Parse overrides from the --with option (key:value,key2:value2).

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

array

Flattened k=>v overrides.

at line 341
static int prune(int $days)

Prune old notifications using the model layer.

Parameters

int $days

Number of days to retain; older rows are deleted.

Return Value

int

Command::SUCCESS on completion.

at line 356
static array|null resolveChannelsOverride(InputInterface $input)

Resolve a channels override list from CLI input.

If the option is omitted/empty, returns NULL so callers can defer to via().

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

array|null

Normalized channels or NULL to defer.

at line 371
static void sendViaNotifiable(object|string $notifiable, Notification $notification, array $payload, array|null $channels)

Deliver a notification via a notifiable (or simulate if notifiable is not an object).

Parameters

object|string $notifiable

Notifiable instance or a sentinel string.

Notification $notification

The notification instance.

array $payload

Per-send payload/overrides.

array|null $channels

Channel override (NULL → use via()).

Return Value

void