Skip to content

Lendable/aggregate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c86120f · Mar 20, 2025
Mar 20, 2025
Mar 4, 2025
May 1, 2024
May 1, 2024
Mar 27, 2023
Sep 29, 2023
Sep 29, 2023
Sep 29, 2023
May 1, 2024
Nov 10, 2024
Jun 28, 2021
Sep 29, 2023
May 26, 2024
Oct 30, 2024
Mar 19, 2025
Apr 2, 2024
Apr 4, 2022
Jan 22, 2024
Sep 29, 2023
May 1, 2024

Repository files navigation

Lendable Aggregate

Latest Stable Version License

Library with supporting functionality to bridge domain and infrastructure interactions for aggregates within event sourcing systems.

This does not help with building out your domain. Rather, it provides interfaces and base functionality for an infrastructure layer to interact with your aggregate classes without requiring them to implement library specific interfaces.

Installation

You can install the library via Composer.

composer require lendable/aggregate

Requirements

  • PHP >= 8.2

Functionality

AggregateIdExtractor

Defines a contract for extracting an AggregateId from domain aggregate objects. Your aggregate class should not hold an AggregateId instance, but instead a domain specific identifier type (e.g. UserId).

AggregateTypeResolver

Defines a contract for resolving an AggregateType from domain aggregate objects. An AggregateType is a classification of aggregate. This is an infrastructure concern, and is aimed towards audit logging alongside an AggregateId and single schema / multiple aggregate storage patterns.

AggregateVersionExtractor

Defines a contract for extracting an AggregateVersion from domain aggregate objects. This is an event sourcing infrastructure concept whereby (usually) the version increases for each event that has taken place to influence the state of the aggregate.

Testing support

The AggregateIdExtractorSpec, AggregateTypeResolverSpec and AggregateVersionExtractorSpec are provided to ease testing of your implementations. Simply extend these classes for your own test suite and implement the hook points.

use Lendable\Aggregate\Testing\AggregateIdExtractorSpec;
use Lendable\Aggregate\AggregateIdExtractor;
use Lendable\Aggregate\AggregateId;

final class FooIdExtractor extends AggregateIdExtractorSpec 
{
    protected function createExtractor(): AggregateIdExtractor
    {
        return new FooIdExtractor();
    }
    
    protected function createExpectedAggregateId(): AggregateId
    {
        return AggregateId::fromString('1406fd13-29d3-44e3-812c-c1cd14e12b38');
    }
    
    protected function createAggregateWithExpectedAggregateId(): object
    {
        return Foo::register(FooId::fromString('1406fd13-29d3-44e3-812c-c1cd14e12b38'));
    }
}