PHPackages                             gpslab/domain-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. [Queues &amp; Workers](/categories/queues)
4. /
5. gpslab/domain-event

ActiveLibrary[Queues &amp; Workers](/categories/queues)

gpslab/domain-event
===================

Tools to create the domain layer of your DDD application

v2.2.0(6y ago)1929.3k↓50%23MITPHPPHP &gt;=5.5.0CI failing

Since Sep 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gpslab/domain-event)[ Packagist](https://packagist.org/packages/gpslab/domain-event)[ Docs](https://github.com/gpslab/domain-event)[ RSS](/packages/gpslab-domain-event/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (18)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/ffed863afb516e9994ff63a417d350f5358bee1c2aeb9cb1d9d928b9fe2dc890/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/domain-event)[![PHP from Travis config](https://camo.githubusercontent.com/b233290ac837ab4d14756e2500083ec731a882429a60ae425c97062f0e1d5443/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/domain-event)[![Total Downloads](https://camo.githubusercontent.com/1a9a8503a2944cc8ecb3dd05c870af587dea39aca3882083f28aaf216a83ca44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/domain-event)[![Build Status](https://camo.githubusercontent.com/ca69b934ebd77270d121917663b519c283a13101c4bb8785da481df4f9a0e4f2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/domain-event)[![Coverage Status](https://camo.githubusercontent.com/1bf37c7de65a4f59a2e2876642e59029c0ca19bb30c94c191fefa8b22c3cefb4/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/domain-event?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1c426f15a2c9b970fef9d36e814c2c4f3743a68477b0b1008c1bfeb727a42b8d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/domain-event/?branch=master)[![StyleCI](https://camo.githubusercontent.com/75c9d905c78af63ffecb1d78f83a93876cbfa34c2c385a30d1dc646cd284159e/68747470733a2f2f7374796c6563692e696f2f7265706f732f36393535323535352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/69552555)[![License](https://camo.githubusercontent.com/fc0a72cd8cbfe52ee94b40f045246a3e9cc0a4fb51ba8f9d3f567656c33e297c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f646f6d61696e2d6576656e742e7376673f6d61784167653d33363030)](https://github.com/gpslab/domain-event)

Domain event
============

[](#domain-event)

Library to create the domain layer of your [Domain-driven design (DDD)](https://en.wikipedia.org/wiki/Domain-driven_design) application

Installation
------------

[](#installation)

Pretty simple with [Composer](http://packagist.org), run:

```
composer require gpslab/domain-event
```

Base usage
----------

[](#base-usage)

Create a domain event

```
use GpsLab\Domain\Event\Event;

final class PurchaseOrderCreatedEvent implements Event
{
    private $customer_id;

    private $create_at;

    public function __construct(CustomerId $customer_id, \DateTimeImmutable $create_at)
    {
        $this->customer_id = $customer_id;
        $this->create_at = $create_at;
    }

    public function customerId()
    {
        return $this->customer_id;
    }

    public function createAt()
    {
        return $this->create_at;
    }
}
```

Raise your event

```
use GpsLab\Domain\Event\Aggregator\AbstractAggregateEvents;

final class PurchaseOrder extends AbstractAggregateEventsRaiseInSelf
{
    private $customer_id;

    private $create_at;

    public function __construct(CustomerId $customer_id)
    {
        $this->raise(new PurchaseOrderCreatedEvent($customer_id, new \DateTimeImmutable()));
    }

    /**
     * The raise() method will automatically call this method.
     * Since it's an event you should never do some tests in this method.
     * Try to think that an Event is something that happened in the past.
     * You can not modify what happened. The only thing that you can do is create another event to compensate.
     * You do not obliged to listen this event and are not required to create this method.
     */
    protected function onPurchaseOrderCreated(PurchaseOrderCreatedEvent $event)
    {
        $this->customer_id = $event->customerId();
        $this->create_at = $event->createAt();
    }
}
```

Create listener

```
class SendEmailOnPurchaseOrderCreated
{
    private $mailer;

    public function __construct($mailer)
    {
        $this->mailer = $mailer;
    }

    public function __invoke(PurchaseOrderCreatedEvent $event)
    {
        $this->mailer->send('recipient@example.com', sprintf(
            'Purchase order created at %s for customer #%s',
            $event->createAt()->format('Y-m-d'),
            $event->customerId()
        ));
    }
}
```

Dispatch events

```
use GpsLab\Domain\Event\Bus\ListenerLocatedEventBus;
use GpsLab\Domain\Event\Listener\Locator\DirectBindingEventListenerLocator;

// first the locator
$locator = new DirectBindingEventListenerLocator();
// you can use several listeners for one event and one listener for several events
$locator->register(PurchaseOrderCreatedEvent::class, new SendEmailOnPurchaseOrderCreated(/* $mailer */));

// then the event bus
$bus = new ListenerLocatedEventBus($locator);

// do what you need to do on your Domain
$purchase_order = new PurchaseOrder(new CustomerId(1));

// this will clear the list of event in your AggregateEvents so an Event is trigger only once
$bus->pullAndPublish($purchase_order);
```

Documentation
-------------

[](#documentation)

- [Base usage](docs/base.md)
- [Raise events in self](docs/raise_in_self.md)
- Listener
    - [Create listener](docs/listener/listener.md)
    - [Create subscriber](docs/listener/subscriber.md)
    - Locator
        - [Direct binding locator](docs/listener/locator/direct_binding.md)
        - [PSR-11 Container locator](docs/listener/locator/psr-11_container.md) *([PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
        - [Symfony container locator](docs/listener/locator/symfony_container.md) *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*
- [Queue](docs/queue/queue.md)
    - [Queue event bus](docs/queue/bus.md)
    - [Pull](docs/queue/pull/pull.md)
        - [Memory queue](docs/queue/pull/memory.md)
        - [Predis queue](docs/queue/pull/predis.md)
    - [Subscribe](docs/queue/subscribe/subscribe.md)
        - [Executing queue](docs/queue/subscribe/executing.md)
        - [AMQP queue](docs/queue/subscribe/amqp.md)
        - [Predis queue](docs/queue/subscribe/predis.md)
    - Serialize command
        - [Simple payload serializer](docs/queue/serialize/simple.md)
        - [Optimized Symfony serializer](docs/queue/serialize/optimized.md)
        - [Payload Symfony serializer](docs/queue/serialize/payload.md)
- Frameworks
    - [Symfony bundle](https://github.com/gpslab/domain-event-bundle)
- [Middleware](https://github.com/gpslab/middleware)
- [Payload](https://github.com/gpslab/payload)

License
-------

[](#license)

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 99.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Recently: every ~168 days

Total

17

Last Release

2477d ago

Major Versions

1.6.x-dev → 2.0.x-dev2017-07-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (229 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

ddddomain-eventinfrastructurephppredissymfonysymfonypredisAMQPdddinfrastructuredomain-event

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gpslab-domain-event/health.svg)

```
[![Health](https://phpackages.com/badges/gpslab-domain-event/health.svg)](https://phpackages.com/packages/gpslab-domain-event)
```

###  Alternatives

[php-amqplib/rabbitmq-bundle

Integrates php-amqplib with Symfony &amp; RabbitMq. Formerly emag-tech-labs/rabbitmq-bundle, oldsound/rabbitmq-bundle.

1.3k20.1M65](/packages/php-amqplib-rabbitmq-bundle)[ecotone/symfony-bundle

Extends Ecotone with Symfony integration

11229.0k1](/packages/ecotone-symfony-bundle)[prooph/humus-amqp-producer

HumusAmqp Producer for Prooph Service Bus

1223.3k3](/packages/prooph-humus-amqp-producer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
