antismok/domain-events-publisher-bundle

symfony bundle for domain event publisher

v1.1 2018-10-29 01:19 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:36 UTC


README

symfony bundle for domain event publisher

Subscribe to domain event

some_domain_listener:
    class: Antismok\Identity\Application\UserCreatedHandler
    tags:
        - { name: domain.event_listener, event: Antismok\Identity\Domain\UserCreatedEvent, method: handle}
declare(strict_types=1);

namespace Antismok\Identity\Application;

use Antismok\Identity\Domain\UserCreatedEvent;

class UserCreatedHandler
{
    public function handle(UserCreatedEvent $event)
    {
        //....
    }
}

Call in model

<?php

declare(strict_types=1);

namespace Antismok\Identity\Domain\Model;

use Antismok\DomainEventPublisher\DomainEventPublisher;
use Antismok\Identity\Domain\UserCreatedEvent;

class User
{
    public function register(string $id, string $login): void
    {
        //.....
        DomainEventPublisher::getInstance()
            ->publish(new UserCreatedEvent($id, $login))
        ;
    }
}

You can use di service @domain_event_dispatcher or @Antismok\DomainEventPublisher\DomainEventPublisher