blacksmith-project/event-manager

This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP library providing event tools

v0.1.0 2019-09-07 10:33 UTC

This package is auto-updated.

Last update: 2020-03-07 11:55:42 UTC


README

Scrutinizer Code Quality Code Coverage

A PHP Library providing tools to manage Events in Domain Driven Design.

How to use it

Make your Entity implements \BSP\EventManager\IRegisterEvent and use \BSP\EventManager\EventRegistration.

Your Entity can now contain its own events.

Example:

class Entity implements IRegisterEvent
{
	use EventRegistration;

	private $id;
	
	private function __construct(UuidInterface $id)
	{
		$this->id = $id;
	}
	
	public static method Register(UuidInterface $id): self
	{
		$entity = new self($id);
		
		$this->recordedEvents[] = new EntityRegistered($id);
		
		return $entity;
	}
}

You now have access to $entity->recordedEvents(), and can loop on those, to dispatch them for example.
Then, you can call $entity->clearRegisteredEvents() to clear them off.