Skip to content

Events

tilttek/journal-bundle

Journal tells each fact to its observer once it is kept. The bundle's observer, DispatchingObserver, hands each event to the application's event dispatcher as it is; without a dispatcher, the events go nowhere.

EventWhenCarries
Tilttek\Journal\Event\EntryDraftedAn entry was drafted, by hand or assembled from a session.the entry, the journal
Tilttek\Journal\Event\EntryChangedIts title, audience, subject or blocks changed, or a block was accepted.the entry, the journal
Tilttek\Journal\Event\EntryPublishedAn entry was published.the entry, the journal, the genre, the author
Tilttek\Journal\Event\EntryWithdrawnA published entry went back to a draft.the entry, the journal
Tilttek\Journal\Event\EntryRemovedAn entry was erased, by Journal::remove() or with its author.the entry, the journal

A listener names the event's class:

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Tilttek\Journal\Event\EntryPublished;
use Tilttek\Journal\Genre;

#[AsEventListener]
final readonly class RewardTheWriter
{
    public function __invoke(EntryPublished $published): void
    {
        if (Genre::Session === $published->genre) {
            // Reward $published->author for the summary of the session.
        }
    }
}

No event carries a title or a text. A listener that sends a Messenger message sends the identifiers alone, and the handler reads the entry again.