@return int */ public function open(); ! /** @return Account */ public function get($accountId); ! /** @return Account[] */ public function findAll($userId); ! /** @return void */ public function credit($accountId, $balance); ! /** @return void */ public function debit($accountId, $balance); }
! /** @return Account[] */ public function findAll($userId); /** @return int */ public function open(); ! /** @return void */ public function credit($accountId, $balance); ! /** @return void */ public function debit($accountId, $balance); Should be void Queries
users ON users.id = tweet.sender_id ! JOIN follows ON follows.followee_id = user.id ! WHERE follows.follower_id = $userId ! ORDER BY tweets.time DESC LIMIT 100
// ... ! public function debit(Money $balance) { if ($this-‐>amount < $balance-‐>getAmount()) { throw new NotEnoughMoneyException( 'Cannot debit more than current amount' ); } ! return $this-‐>apply(new AccountWasCredited( $this-‐>accountId, $balance-‐>getAmount(), $balance-‐>getCurrency() )); } }
in datastore Example Two debits of 100€ must not be accepted if only 150€ left Load aggregate from EventStore: 150€ Create AccountWasDebited event Append event in datastore Event must NOT be appended twice
private $uncommittedEvents = array(); ! private $playhead = -‐1; /** * Applies an event. * The event is added to the list of uncommited events. */ public function apply($event) { $this-‐>playhead++; ! $this-‐>uncommittedEvents[] = DomainMessage::recordNow( $this-‐>getAggregateRootId(), $this-‐>playhead, new Metadata(array()), $event ); } }