potfur / journal
dev-master
2016-03-26 16:39 UTC
Requires
- php: >=5.6
Requires (Dev)
- league/tactician: ^1.0
- phpspec/phpspec: ^2.4
- phpunit/phpunit: ^5.2
- symfony/event-dispatcher: ^3.0
This package is not auto-updated.
Last update: 2024-12-21 20:36:01 UTC
README
Heavily inspired by EventCentric.Core event sourcing framework.
How does it work
Example is a simplified case of bank accounts with two basic actions: Deposit
and Withdraw
to increase and
decrease balance.
There is also a composite process - Transfer
to show how sagas/process managers can be implemented.
Account
is a aggregate root, a class that is subject to actions from commands,- each action that has effect on
Account
will create at least oneDomainEvent
instance, describing what happened, eg.MoneyWereDepositedEvent
which says that some amount of money were deposited onAccount
Account
stores those events in order of occurrence,UnitOfWork
tracks events inAccount
, and when it is committed - all new events will be sent toEventStore
,EventStore
will store new events asEventStream
- an immutable list of changes for this account.- when new action occurs,
UnitOfWork
will reconstituteAccount
from stored events, - when ever event is stored, event emitter sends it to all presenters so they can react to it,
- presenters
AccountHistoryPresenter
andAccountBalancePresenter
subscribe to events and update data for read models, eg. as reaction toMoneyWereDepositedEvent
,AccountHistoryPresenter
will add new entry that says when and what amount was deposited.AccountBalancePresenter
will increase accounts balance.
Example uses Tactician for command bus and Event Dispatcher for emitting events, but they can be replaced with anything else.
Stuff that's missing
- snapshots
- more elaborate example
License
See LICENSE.