open-solid/domain-event-bundle

Symfony bundle for domain events

v1.0.0 2024-04-30 06:22 UTC

This package is auto-updated.

Last update: 2024-04-30 06:24:32 UTC


README

A Symfony bundle for handling domain events (https://github.com/open-solid/domain-event).

Installation

$ composer require open-solid/domain-event-bundle

Usage

use OpenSolid\DomainEvent\DomainEvent;
use OpenSolid\DomainEventBundle\Attribute\AsDomainEventSubscriber;

class UserRegistered extends DomainEvent
{
}

#[AsDomainEventSubscriber]
class UserRegisteredHandler
{
    public function __invoke(UserRegistered $event): void
    {
        // Handle the event
    }
}

class UserService
{
    public function __construct(private DomainEventPublisher $publisher)
    {
    }

    public function registerUser(): void
    {
        // Register the user

        $this->publisher->publish(new UserRegistered('uuid'));
    }
}

License

This software is published under the MIT License