PHPackages                             phariscope/event - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phariscope/event

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phariscope/event
================

To implement events in domain driven design or other styles projects with PHP

1.2.1(9mo ago)09.2k↑78.6%1MITPHPPHP &gt;=8.1

Since Sep 24Pushed 9mo agoCompare

[ Source](https://github.com/phariscope/Event)[ Packagist](https://packagist.org/packages/phariscope/event)[ Docs](https://github.com/phariscope/Event)[ RSS](/packages/phariscope-event/feed)WikiDiscussions 1.x Synced yesterday

READMEChangelog (5)Dependencies (7)Versions (14)Used By (1)

Installation
============

[](#installation)

```
composer require phariscope/event
```

Usage
=====

[](#usage)

Steps are:

- Create a domain event (name + past tense verb, example: `AccountCreated` extends `Phariscope\\Event\\Psr14\\Event`).
- Dispatch this event.
- Distribute events (manually, or enable immediate distribution).

Somewhere else:

- create a listener for an event (example: class `SendEmailWhenAccountCreatedListener` implements `Phariscope\\Event\\Psr14\\ListenerInterface`)
- register the listener; when the event is distributed the listener will handle it and do what it has to do

Sample usage in an aggregate constructor
----------------------------------------

[](#sample-usage-in-an-aggregate-constructor)

You SHOULD dispatch a domain event from an aggregate to signal its creation. This helps apply the Single Responsibility Principle: cross‑cutting concerns (emails, projections, integrations) live in listeners rather than inside the aggregate.

```
