eventsauce/laravel-eventsauce

Integration support for EventSauce with the Laravel framework.

0.1.0 2019-08-29 09:49 UTC

This package is auto-updated.

Last update: 2019-12-21 15:25:30 UTC


README

68747470733a2f2f6576656e7473617563652e696f2f7374617469632f6c6f676f2e737667

Laravel EventSauce

Packagist Version Travis Downloads

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

Table of Contents

Requirements

  • PHP ^7.3
  • Laravel ^6.0

Installation

You can install the library through Composer. This will also install the main EventSauce library.

composer require eventsauce/laravel-eventsauce

Configuration

You can publish the config file with the following command:

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

Migrations

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

php artisan migrate

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

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

Default Connection

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

EVENTSAUCE_CONNECTION=mysql

Default Table

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

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:

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:

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:

'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:

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

Thanks to Frank De Jonge for building EventSauce. Thanks to Freek Van der Herten and Spatie's Laravel EventSauce library for inspiration to some of the features in this package.

License

The MIT License. Please see the License File for more information.