Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eventsauce Snapshotting Laravel Package

andreo/eventsauce-snapshotting

Extended snapshotting components for EventSauce: Doctrine DBAL snapshot repository plus versioned snapshotting support. Includes version-aware aggregate repository, snapshot version inflector/comparator, and VersionedSnapshotState for evolving snapshot schemas on PHP 8.2+.

View on GitHub
Deep Wiki
Context7

eventsauce-snapshotting 3.0

Extended snapshot components for EventSauce

About Snapshotting

Installation

composer require andreo/eventsauce-snapshotting

Previous versions

Requirements

  • PHP >=8.2
  • Doctrine Dbal ^3.1

Doctrine snapshot repository

use Andreo\EventSauce\Snapshotting\Doctrine\DoctrineSnapshotRepository;

new DoctrineSnapshotRepository(
    connection: $connection, // Doctrine\DBAL\Connection
    tableName: $tableName,
    serializer: $serializer, // Andreo\EventSauce\Snapshotting\Serializer\SnapshotStateSerializer
    uuidEncoder: $uuidEncoder, // EventSauce\UuidEncoding\UuidEncoder
    tableSchema: $tableSchema // Andreo\EventSauce\Snapshotting\Repository\Table\SnapshotTableSchema
)

Versioning

Repository

use Andreo\EventSauce\Snapshotting\Versioned\AggregateRootRepositoryWithVersionedSnapshotting;

new AggregateRootRepositoryWithVersionedSnapshotting(
    aggregateRootClassName: $aggregateRootClassName,
    messageRepository: $messageRepository
    regularRepository: $regularRepository, // EventSauce\EventSourcing\AggregateRootRepository
    snapshotVersionInflector: $snapshotVersionInflector, // Andreo\EventSauce\Snapshotting\Repository\Versioned\SnapshotVersionInflector
    snapshotVersionComparator: $snapshotVersionComparator // Andreo\EventSauce\Snapshotting\Repository\Versioned\SnapshotVersionComparator
);

Versioned Snapshot State


use Andreo\EventSauce\Snapshotting\Versioned\VersionedSnapshotState;

final class FooSnapshotStateV2 implements VersionedSnapshotState {

    public static function getSnapshotVersion(): int|string|Stringable
    {
        return 2;
    }
}

Example of aggregate


use Andreo\EventSauce\Snapshotting\Aggregate\VersionedSnapshottingBehaviour;
use EventSauce\EventSourcing\AggregateRootBehaviour;
use EventSauce\EventSourcing\AggregateRootId;
use EventSauce\EventSourcing\Snapshotting\AggregateRootWithSnapshotting;

final class FooAggregate implements AggregateRootWithSnapshotting
{
    use AggregateRootBehaviour;
    use VersionedSnapshottingBehaviour;

    // Create snapshot method must have type hint of VersionedSnapshotState implementation (with default SnapshotVersionInflector)
    protected function createSnapshotState(): FooSnapshotStateV2
    {
        return new FooSnapshotStateV2();
    }

    protected static function reconstituteFromSnapshotState(AggregateRootId $id, $state): AggregateRootWithSnapshotting
    {
        assert($state instanceof FooSnapshotStateV2);
    }
}

Conditional Strategy



interface ConditionalSnapshotStrategy
{
    public function canStoreSnapshot(AggregateRootWithSnapshotting $aggregateRoot): bool;
}

Built-in strategies

Every n event


use Andreo\EventSauce\Snapshotting\Conditional\AggregateRootRepositoryWithConditionalSnapshot;use Andreo\EventSauce\Snapshotting\Conditional\EveryNEventConditionalSnapshotStrategy;

new AggregateRootRepositoryWithConditionalSnapshot(
    regularRepository: $regularRepository, // EventSauce\EventSourcing\Snapshotting\AggregateRootRepositoryWithSnapshotting
    conditionalSnapshotStrategy: new EveryNEventConditionalSnapshotStrategy(numberOfEvents: 200) # or your implementation
);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle