texdc/momento

领域事件的库

v2.0.0 2017-10-14 20:44 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:05:58 UTC


README

受Vaughn Vernon的《实现领域驱动设计》一书和其部分代码示例启发的简单领域事件库。Vaughn Vernon's book Implementing Domain Driven Design, and some of his code samples.

Latest Build Dependencies Latest Stable Version Total Downloads License

事件处理器

namespace My\Event;

use texdc\momento\AbstractEventHandler;
use texdc\momento\EventInterface;

final class Handler extends AbstractEventHandler
{
    protected static $validEventTypes = [
        FooEvent::TYPE,
        BarEvent::TYPE,
    ];
    
    public function __invoke(EventInterface $anEvent)
    {
        $type = $anEvent->eventType();
        $this->guardValidEventType($type);
        call_user_func([$this, $type], $anEvent);
    }
    
    // ...
}