Skip to content

Commit

Permalink
Add some initial docs
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Sep 30, 2019
1 parent f5682b3 commit dc84343
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
111 changes: 110 additions & 1 deletion README.md
Expand Up @@ -16,7 +16,116 @@
</a>
</p>

This library is a work in progress. Docs coming soon...
This library is a work in progress. More docs coming soon...

## Table of Contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Acknowledgments](#acknowledgments)
- [License](#license)

## Requirements

- PHP ^7.3
- Laravel ^6.0

## Installation

You can install the library through [Composer](https://getcomposer.org). This will also install [the main EventSauce library](https://github.com/EventSaucePHP/EventSauce).

```bash
composer require eventsauce/laravel-eventsauce
```

## Configuration

### Migrations

The default `domain_messages` table will be loaded in through the library's service provider and migrated with:

```bash
php artisan migrate
```

You can also publish it and modify it as you see fit with the following command:

```bash
php artisan vendor:publish --tag="eventsauce-migrations"
```

### Config Options

Publish the config file with the following command:

```bash
php artisan vendor:publish --tag="eventsauce-config"
```

#### Default Connection

The default database connection can be modified by setting the `EVENTSAUCE_CONNECTION` env variable:

```dotenv
EVENTSAUCE_CONNECTION=mysql
```

#### Default Table

The default table name for your domain messages can be set with the `EVENTSAUCE_TABLE` env variable:

```dotenv
EVENTSAUCE_TABLE=event_store
```

## Generating Commands & Events

EventSauce can generate commands and events for you so you don't need to write these yourself. First, define a `commands_and_events.yml` file which contains your definitions:

```yaml
namespace: App\Domain\Registration
commands:
ConfirmUser:
fields:
identifier: RegistrationAggregateRootId
user_id: int
events:
UserWasConfirmed:
fields:
identifier: RegistrationAggregateRootId
user_id: int
```

Then define the input and output output file in the AggregateRootRepository:

```php
final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
...

/** @var string */
protected static $inputFile = __DIR__.'/commands_and_events.yml';

/** @var string */
protected static $outputFile = __DIR__.'/commands_and_events.php';
}
```

And register the AggregateRootRepository in your `eventsauce.php` config file:

```php
'repositories' => [
\App\Domain\Registration\RegistrationAggregateRootRepository::class,
],
```

You can now generate commands and events for all repositories that you've added by running the following command:

```bash
php artisan eventsauce:generate
```

For more info on creating events and commands with EventSauce, as well as how to define different types, see: https://eventsauce.io/docs/getting-started/create-events-and-commands

## Acknowledgments

Expand Down
1 change: 0 additions & 1 deletion tests/Fixtures/commands_and_events.yml
@@ -1,4 +1,3 @@
---
namespace: Tests\Fixtures

commands:
Expand Down

0 comments on commit dc84343

Please sign in to comment.