Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventSourcing] Experimenting with new way to complete things to make it a little easier #111

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JoshuaEstes
Copy link
Member

@JoshuaEstes JoshuaEstes commented Nov 5, 2023

The current way of setting this up is super verbose. Needs to be a little quicker and easier to do all this stuff.


$config = new Configuration([
  'paths' => [__DIR__ . '/src'],
  'driver' => new AttributeDriver(),
  'container' => $container,
]);

$manager = new AggregateManager($config);

// --OR--

$builder = new ConfigurationBuilder();
$builder->setPaths([__DIR__ . '/src']);
$builder->setDriver(new AttributeDriver());

$manager = new AggregateManager($builder->getConfiguration());

Finds all the files in paths and uses the AttributeDriver to read them. If they are Aggregates, it will register them to be managed by the AggregateManager. The AggregateManager will be the primary way to interact with everything. Drivers could be YamlDriver, XmlDriver, AnnotationDriver, etc.


#[AsAggregate]
class UserAggregate
{
  #[ApplyEvent(Created::class)]
  protected function applyUsernameOnCreated(Created $event): void {}

  #[ApplyEvent(Created::class)]
  protected function applyEmailOnCreated(Created $event): void {}
}

Using attributes, you can set upserters and other related metadata. If some aren't found, it should default to sane values. This is where the aggregate would all be configured.


$aggregate = $manager->find(UserAggregate::class, 'unique-id');

$user = new UserAggregate('unique-id');
$user->create($command);
$manager->persist($user);

$aggregateMetadata = $manager->getMetadata(UserAggregate::class);

The metadata would contain all the relevant information about the aggregate.


  • Documentation is updated
  • Use Event Sourcing Contract

@github-actions github-actions bot added documentation Improvements or additions to documentation EventSourcing labels Nov 5, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2023

Codecov Report

Attention: 78 lines in your changes are missing coverage. Please review.

Comparison is base (e645565) 65.85% compared to head (39f6009) 64.04%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #111      +/-   ##
============================================
- Coverage     65.85%   64.04%   -1.81%     
- Complexity      886      918      +32     
============================================
  Files           145      164      +19     
  Lines          2308     2381      +73     
============================================
+ Hits           1520     1525       +5     
- Misses          788      856      +68     
Files Coverage Δ
...nt/EventSourcing/Aggregate/AbstractAggregateId.php 100.00% <100.00%> (ø)
...omponent/EventSourcing/Message/AbstractMessage.php 100.00% <100.00%> (ø)
...nent/EventSourcing/Aggregate/AbstractAggregate.php 97.43% <50.00%> (+20.69%) ⬆️
...HP/Component/EventSourcing/Mapping/AggregateId.php 0.00% <0.00%> (ø)
...mponent/EventSourcing/Mapping/AggregateVersion.php 0.00% <0.00%> (ø)
...PHP/Component/EventSourcing/Mapping/ApplyEvent.php 0.00% <0.00%> (ø)
...HP/Component/EventSourcing/Mapping/AsAggregate.php 0.00% <0.00%> (ø)
.../Component/EventSourcing/Mapping/AsAggregateId.php 0.00% <0.00%> (ø)
...nt/EventSourcing/Mapping/AsAggregateRepository.php 0.00% <0.00%> (ø)
...onent/EventSourcing/Mapping/AsAggregateVersion.php 0.00% <0.00%> (ø)
... and 12 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JoshuaEstes JoshuaEstes added this to the v2.x milestone Nov 8, 2023
@JoshuaEstes JoshuaEstes removed this from the v2.x milestone Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants