Skip to content

Commit

Permalink
Merge pull request #54 from patchlevel/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura authored Dec 11, 2021
2 parents c897366 + 7d65845 commit 4e86b02
Show file tree
Hide file tree
Showing 9 changed files with 1,292 additions and 5 deletions.
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@ Small lightweight event-sourcing library.
composer require patchlevel/event-sourcing
```

## define aggregates
## integration

* [Symfony](https://github.com/patchlevel/event-sourcing-bundle)
* [Psalm](https://github.com/patchlevel/event-sourcing-psalm-plugin)

## documentation

* [Aggregate](docs/aggregate.md)
* [Repository](docs/repository.md)
* [Processor](docs/processor.md)
* [Projection](docs/projection.md)
* [Snapshots](docs/snapshots.md)
* [Pipeline](docs/pipeline.md)
* [Tests](docs/tests.md)

## Getting Started

### define aggregates

```php
<?php declare(strict_types=1);
Expand Down Expand Up @@ -85,7 +102,7 @@ final class Profile extends AggregateRoot
}
```

## define events
### define events

```php
<?php declare(strict_types=1);
Expand Down Expand Up @@ -126,7 +143,7 @@ final class ProfileCreated extends AggregateChanged
}
```

# define projections
### define projections

```php
<?php declare(strict_types=1);
Expand Down Expand Up @@ -163,6 +180,11 @@ final class MessageProjection implements Projection
'created_at' => $message->createdAt()->format(DATE_ATOM),
]);
}

public function create(): void
{
// do nothing (collection will be created lazy automatically)
}

public function drop(): void
{
Expand All @@ -171,7 +193,39 @@ final class MessageProjection implements Projection
}
```

## usage
### configuration

```php
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\Projection\DefaultProjectionRepository;
use Patchlevel\EventSourcing\Projection\ProjectionListener;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager;
use Patchlevel\EventSourcing\Store\SingleTableStore;

$messageProjection = new MessageProjection($this->connection);
$projectionRepository = new DefaultProjectionRepository(
[$messageProjection]
);

$eventStream = new DefaultEventBus();
$eventStream->addListener(new ProjectionListener($projectionRepository));
$eventStream->addListener(new SendEmailProcessor());

$store = new SingleTableStore(
$this->connection,
[Profile::class => 'profile'],
'eventstore'
);

$repository = new Repository($store, $eventStream, Profile::class);

// create tables
$profileProjection->create();
(new DoctrineSchemaManager())->create($store);
```

### usage

```php
<?php declare(strict_types=1);
Expand All @@ -198,4 +252,4 @@ final class CreateProfileHandler
$this->profileRepository->store($profile);
}
}
```
```
Loading

0 comments on commit 4e86b02

Please sign in to comment.