Download the PHP package agencelex/notifications without Composer
On this page you can find all versions of the php package agencelex/notifications. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agencelex/notifications
More information about agencelex/notifications
Files in agencelex/notifications
Package notifications
Short Description A Laravel-style notification system for TYPO3. Any PHP code — a controller, an Extbase plugin, a domain service, a Scheduler task, a middleware — can send a notification to any object that uses the Notifiable trait.
License GPL-2.0-or-later
Homepage https://extensions.typo3.org/extension/lex_notifications
Informations about the package notifications
lex_notifications — TYPO3 Notification System
A Laravel-style notification system for TYPO3. Any PHP class can send a
notification to any object that uses the Notifiable trait — through any
combination of channels (email, database, Slack, …).
There is no constraint on the direction: a frontend user can notify another
frontend user, an extension can alert a backend user, a Scheduler task can
email an address with no domain model at all. If it uses Notifiable, it
can receive notifications.
A backend module (Web > Notifications) is included for editors who need to compose and send messages to frontend users. It also serves as a reference implementation for dispatching batch notifications from PHP code.
Requirements
| Dependency | Version |
|---|---|
| TYPO3 CMS | ^13.4 || ^14 |
| PHP | ^8.2 |
| nesbot/carbon | ^3.2 |
| illuminate/collections | ^12.69 |
Installation
Quick Start
1. Make any class a notification recipient (optional)
2. Create a notification
3. Send it
Who Can Be a Recipient?
Any object that uses the Notifiable trait — regardless of class hierarchy:
On-Demand Notifications
Sometimes the recipient is not a model at all: a guest who left an email
address, a support mailbox, a Teams room. Instead of writing a throwaway
class, ask the NotificationManager for an anonymous notifiable and give
it a route for each channel:
route() and routes() return a Lex\Notifications\AnonymousNotifiable.
It uses the Notifiable trait, so notify() (queued if ShouldQueue) and
notifyNow() (immediate) work as usual, and so does
$this->notificationDispatcher->send($anonymous, ...).
Things to know:
- The route is whatever the channel expects. For
mail, it can be a string or aSymfony\Component\Mime\Address. For a custom channel, it can be any value (webhook URL, room ID, phone number…). via()still decides. Only the channels returned by the notification'svia()are used. A routed channel thatvia()doesn't return is ignored.- The
databasechannel is not supported. An anonymous recipient has no UID to store, so routing todatabasethrows anInvalidArgumentException. - Validation:
route()checks that the channel is registered and throws anInvalidArgumentExceptionif it isn't.routes()and any chained->route()calls don't check; an unknown channel only fails when the notification is sent. - Queued on-demand notifications go through Symfony Messenger like any
other. With an asynchronous transport, routes must be serializable (strings,
Addressobjects…).
Custom channels should read the route with
$notifiable->routeNotificationFor('<channel>', $notification). That works for
both anonymous notifiables and models: on a model, the Notifiable trait
forwards the call to routeNotificationFor<Channel>() (e.g.
routeNotificationForSlack()).
Channels
Two built-in channels are included:
| Key | Class | Description |
|---|---|---|
mail |
EmailChannel |
HTML/plain-text email via TYPO3 mail system |
database |
DatabaseChannel |
Persisted in-app notifications via Extbase |
Adding a Custom Channel
Implement ChannelInterface — the channel is automatically registered with no
additional configuration required:
Then return the key from via():
Then implement the route method in each notifiable that could be notified through this channel:
If that route is missed, the system will skip the channel when sending the notifications to the notifiable.
The NotificationManager resolves the channel by its key at send time. To ensure a custom channel is properly detected and registered into the manager's iterator, you must assign the notifications.channel tag to your class.
You can achieve this in one of three ways:
1. Declaration in Services.yaml
Add your concrete channel class manually with the required tag in your extension's Configuration/Services.yaml:
2. Using #[AutoconfigureTag] in the channel class (Recommended)
Keep your YAML file clean by adding the Symfony attribute directly above your class definition:
3. Using #[Autoconfigure] in the channel class
If you need to change other service options (like visibility) while registering the tag, you can pass the tags directly into the #[Autoconfigure] attribute:
Queue Support
Implement the ShouldQueue marker interface to dispatch via Symfony Messenger:
Run the worker:
Call notifyNow() / sendNow() to bypass the queue at any time.
Notification Levels (RFC 5424)
| Constant | Value |
|---|---|
NotificationLevel::LEVEL_INFO |
0 |
NotificationLevel::LEVEL_NOTICE |
1 |
NotificationLevel::LEVEL_WARNING |
2 |
NotificationLevel::LEVEL_ERROR |
3 |
NotificationLevel::LEVEL_CRITICAL |
4 |
NotificationLevel::LEVEL_ALERT |
5 |
NotificationLevel::LEVEL_EMERGENCY |
6 |
Backend Module
Web > Notifications lets editors:
- Compose messages (subject, body, level, link)
- Target frontend users or groups, with optional exclusions
- Choose delivery channels (email and/or database)
- Send immediately or queue for later, and resend at any time
The module source (Classes/Controller/Backend/NotificationController.php)
is intentionally simple and can be used as a reference for dispatching
batch notifications from PHP code.
Reading In-App Notifications
Development
Running the Tests
The extension ships two test suites:
| Suite | Location | What it covers |
|---|---|---|
| Unit | Tests/Unit/ |
Manager, channels, traits, models, queue handler. No TYPO3 instance. |
| Functional | Tests/Functional/ |
A real TYPO3 instance: DI wiring, email delivery, database storage, queue handler, repositories, custom channels registered by another extension, and every public way of sending a notification. |
The functional tests load a fixture extension
(Tests/Functional/Fixtures/Extensions/notifications_test). It plays the role
of a third-party integrator: it registers custom channels and captures sent
emails in memory, so no mail is ever sent. By default they use SQLite, so
no database server is needed.
Without DDEV
Requires PHP 8.2+ (with pdo_sqlite) and Composer, run from the extension
directory:
Composer cannot install the dependencies on an exFAT volume (plugin installation fails). Use an APFS/ext4 disk, or DDEV.
With DDEV
The extension directory contains a DDEV configuration:
The functional tests create one database per test class (prefixed with
typo3DatabaseName), so the database user needs CREATE DATABASE
privileges. That's why the example uses root.
Useful options
Any other database can be used through the typo3DatabaseDriver,
typo3DatabaseHost, typo3DatabasePort, typo3DatabaseUsername,
typo3DatabasePassword and typo3DatabaseName environment variables.
Documentation
Full documentation: https://docs.typo3.org/p/agencelex/notifications/1.4/en-us/
License
GPL-2.0-or-later — see LICENSE.
Author
All versions of notifications with dependencies
typo3/cms-core Version ^13.4 || ^14.3
nesbot/carbon Version ^3.2
illuminate/collections Version ^12.69