PHP code example of syeedalireza / symfony-eventsourcing-toolkit
1. Go to this page and download the library: Download syeedalireza/symfony-eventsourcing-toolkit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
syeedalireza / symfony-eventsourcing-toolkit example snippets
// Define your aggregate
class BankAccount extends AggregateRoot
{
private Money $balance;
public function deposit(Money $amount): void
{
$this->recordThat(new MoneyDeposited($amount));
}
protected function applyMoneyDeposited(MoneyDeposited $event): void
{
$this->balance = $this->balance->add($event->amount);
}
}
// Use the event store
$eventStore->save($account);
$history = $eventStore->load($accountId);