for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Domain\Snapshotting\Policy;
use Domain\Aggregates\AggregateRoot;
use Domain\Snapshotting\SnapshottingPolicy;
/**
* @author Sebastiaan Hilbers <[email protected]>
*/
class IntervalBased implements SnapshottingPolicy
{
private $interval;
public function __construct($interval = 3)
$this->interval = $interval;
}
public function shouldCreateSnapshot(AggregateRoot $root)
if ($root->hasChanges()) {
$lastEvent = $root->getChanges()[count($root->getChanges()) -1];
$lastVersion = $lastEvent->getVersion();
for ($i = $root->getVersion(); $i <= $lastVersion; $i++) {
if ($i % $this->interval == 0) {
return true;
return false;