Search by

stijnhau / messaging-bundle

stijnhau

Private messages between users for Symfony apps: inbox, sent box, read state, per-side deletion and moderation.

Package info

github.com/stijnhau/messaging-bundle

Type:symfony-bundle

pkg:composer/stijnhau/messaging-bundle

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-28 19:42 UTC

This package is auto-updated.

Last update: 2026-11-28 19:49:24 UTC


README

Private messages between users for Symfony apps: inbox and sent box, read state, each side deleting its own copy, and moderators removing a message. Shared by CityWars, Crime-Life and F1Manager.

Piece What it does
Model\AbstractMessage Doctrine mapped superclass: sender, recipient, subject, body (sanitized HTML), sent/read, deleted by sender/recipient, removed, in reply to. The app maps a concrete subclass with any class and table name, and may add columns, indexes or #[ORM\AttributeOverrides].
Service\Mailbox send(), open() (marks it read for the recipient), delete() (one side's copy; purged once both deleted), remove() (moderation).
Query\MailboxReader Inbox and sent box a page at a time, unread count, findVisible(). inboxQuery()/sentQuery() return a QueryBuilder you can narrow (a search) before page().
Service\ContentPolicy The subject/body checks plus sanitizing, for system messages the app writes itself.

Block or ignore lists, mutes and rate limits are app-specific. They plug in as send guards. There's no ready-made UI: each app keeps its own pages on top of these services.

Install

composer require stijnhau/messaging-bundle
  1. The user entity implements Stijnhau\MessagingBundle\Model\MessageParticipantInterface (getId()).

  2. Map a message entity:

    #[ORM\Entity]
    #[ORM\Index(name: 'idx_message_inbox', columns: ['recipient_id', 'sent_at'])]
    class Message extends AbstractMessage {}
  3. Configure config/packages/stijnhau_messaging.yaml:

    stijnhau_messaging:
        user_class: App\Entity\User
        message_class: App\Entity\Message
        per_page: 20
        subject_max_length: 150        # at most 150, the column's length
        subject_required: true
        body_max_length: 4000          # length of the sanitized HTML
        purge_when_deleted_by_both: true
        sanitizer: ~                   # an HtmlSanitizerInterface service id; default: safe elements
  4. bin/console make:migration. The bundle ships no migrations.

Time comes from the clock service (symfony/clock), so a MockClock drives it in tests.

Hooks

  • Who may send: implement Security\SendGuardInterface (block lists, mutes, rate limits). Every implementation runs before each message. Throw to refuse, with a MessagingException or your own exception.
  • Keeping deleted messages: implement Security\MessageRetentionInterface. A message both sides deleted stays if any implementation mustKeep() it (for example, it was reported).
  • Events: MessageSentEvent is dispatched inside the transaction that saves the message, so a listener's writes (a notification, a Doctrine-transport Messenger message) commit with it. There are also MessageReadEvent, MessageDeletedEvent (with $purged) and MessageRemovedEvent.
  • Errors: MessagingException::getKey() is a key in the stijnhau_messaging translation domain (en/nl/fr included). $e->trans($translator) gives the text.

Development

composer install
vendor/bin/phpunit

License

MIT, see LICENSE.