Events
tilttek/journal-bundleJournal 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.
| Event | When | Carries |
|---|---|---|
Tilttek\Journal\Event\EntryDrafted | An entry was drafted, by hand or assembled from a session. | the entry, the journal |
Tilttek\Journal\Event\EntryChanged | Its title, audience, subject or blocks changed, or a block was accepted. | the entry, the journal |
Tilttek\Journal\Event\EntryPublished | An entry was published. | the entry, the journal, the genre, the author |
Tilttek\Journal\Event\EntryWithdrawn | A published entry went back to a draft. | the entry, the journal |
Tilttek\Journal\Event\EntryRemoved | An 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.