lendable / aggregate
Lendable Aggregate Library
Installs: 67 481
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 40
Forks: 1
Open Issues: 3
Requires
- php: ^8.2
- beberlei/assert: ^3.3
- ramsey/uuid: ^4.5
Requires (Dev)
- ergebnis/composer-normalize: ^2.42.0
- lendable/composer-license-checker: ^1.2.0
- php-cs-fixer/shim: ^3.54.0
- php-parallel-lint/php-parallel-lint: ^1.4.0
- phpstan/phpstan: ^1.10.67
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-phpunit: ^1.3.16
- phpstan/phpstan-strict-rules: ^1.5.5
- phpunit/phpunit: ^11.1.3
- qossmic/deptrac: ^2.0.0-alpha
- rector/rector: ^1.0.4
This package is auto-updated.
Last update: 2024-11-04 23:16:06 UTC
README
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')); } }