Download the PHP package supplycart/laravel-eventsauce without Composer
On this page you can find all versions of the php package supplycart/laravel-eventsauce. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download supplycart/laravel-eventsauce
More information about supplycart/laravel-eventsauce
Files in supplycart/laravel-eventsauce
Package laravel-eventsauce
Short Description Integration support for EventSauce with the Laravel framework.
License MIT
Informations about the package laravel-eventsauce
Laravel EventSauce
This library allows you to easily integrate EventSauce with your Laravel application. It takes out the tedious work of having to set up your own message dispatcher and provides an easy API to set up consumers, and more. It also comes with a range of scaffolding console commands to easily generate the boilerplate needed to get started with an Event Sourced application.
⚠️ While already usable, this library is currently still a work in progress. More documentation and features will be added over time. We appreciate pull requests that help extend and improve this project.
Requirements
- PHP 7.4 or higher
- Laravel 8.0 or higher
Installation
Before installing a new package it's always a good idea to clear your config cache:
You can install the library through Composer. This will also install the main EventSauce library.
Configuration
You can publish the config file with the following command:
Migrations
The default domain_messages
table will be loaded in through the library's service provider and migrated with:
You can also publish it and modify it as you see fit with the following command:
Default Connection
The default database connection can be modified by setting the EVENTSAUCE_CONNECTION
env variable:
Default Table
The default table name for your domain messages can be set with the EVENTSAUCE_TABLE
env variable:
Scaffolding
Laravel EventSauce comes with some commands that you can use to scaffold objects and files which you'll need to build your Event Sourced app. These commands take out the tedious work of writing these yourself and instead let you focus on actually writing your domain logic.
Generating Aggregate Roots
Laravel EventSauce can generate aggregate roots and its related files for you. By using the make:aggregate-root
command, you can generate the following objects and files:
- The
AggregateRoot
- The
AggregateRootId
- The
AggregateRootRepository
- The migration file
To generate these files for a "Registration" process, run the following command:
This will scaffold the following files:
App\Domain\Registration
App\Domain\RegistrationId
App\Domain\RegistrationRepository
database/migrations/xxxx_xx_xx_create_registration_domain_messages_table.php
These are all the files you need to get started with an https://github.com/EventSaucePHP/LaravelEventSauce.
Generating Consumers
Laravel EventSauce can also generate consumers for you. For example, run the make:consumer
command to generate a SendEmailConfirmation
process manager:
This will create a class at App\Domain\SendEmailConfirmation
where you can now define handle{EventName}
methods to handle events.
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:
Then define the input and output output file in the AggregateRootRepository:
And register the AggregateRootRepository in your eventsauce.php
config file:
You can now generate commands and events for all repositories that you've added by running the following command:
For more info on creating events and commands with EventSauce, as well as how to define different types, see the EventSauce documentation.
Usage
Aggregate Roots
More docs coming soon...
Aggregate Root Repositories
More docs coming soon...
Queue Property
You can instruct Laravel to queue all consumers onto a specific queue by setting the $queue
property:
This will force all consumers who have the ShouldQueue
contract implemented to make use of the registrations
queue instead of the default queue defined in your queue.php
config file.
Consumers
Consumers are classes that react to events fired from your aggregate roots. There's two types of consumers: projections and process managers. Projections update read models (think updating data in databases, updating reports,...) while process managers handle one-time tasks (think sending emails, triggering builds, ...). For more information on how to use them, check out EventSauce's Reacting to Events documentation.
A SendEmailConfirmation
process manager, for example, can look like this:
Within this consumer you always define methods following the handle{EventName}
specification.
Registering Consumers
After writing your consumer, you can register them with the $consumers
property on the related AggregateRootRepository
:
The sequence of adding consumers shouldn't matter as the data handling within these consumers should always be treated as independent from each other.
Queueing Consumers
By default, consumers are handled synchronous. To queue a consumer you should implement the ShouldQueue
contract on your consumer class.
By doing so, we'll instruct Laravel to queue the consumer and let the data handling be done at a later point in time. This is useful to delay long-running data processing.
Changelog
Check out the CHANGELOG in this repository for all the recent changes.
Maintainers
This project is currently looking for a new maintainer.
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
Laravel EventSauce is open-sourced software licensed under the MIT license.
All versions of laravel-eventsauce with dependencies
ext-json Version *
eventsauce/eventsauce Version ^1.0
illuminate/bus Version ^8.0|^9.0|^10.0|^11.0
illuminate/container Version ^8.0|^9.0|^10.0|^11.0
illuminate/queue Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
ramsey/uuid Version ^3.8|^4.0