There were no changes to the public API, we only performed internal cleanup and provided support for Laravel 9
The EventHandler interface was changed:
- public function handles(): array;
+ public function handles(StoredEvent $storedEvent): bool;
- public function handle(StoredEvent $event);
+ public function handle(StoredEvent $storedEvent): void;- Stored events now have an
event_versioncolumn and property. You must add this migration manually. - Make sure any aggregate roots with constructors call the parent
__constructmethod - Event listeners in aggregate roots, projectors and reactors all rely on type hints rather than method naming. Make sure all your methods use the appropriate type hints (the method name no longer matters).
$handlesEventson Projectors and Reactors isn't supported anymore. - Dependency injection in handlers isn't supported anymore, use constructor injection instead
$storedEventand$aggregateRootUuidare no longer passed to event handler methods. Use$event->storedEventId()and$event->aggregateRootUuid()instead. (#180)- The
EloquentStoredEvent::query()->uuid()is nowEloquentStoredEvent::query()->whereAggregateRoot() AggregateRoot::$allowConcurrencyis no longer supported- Event handlers are no longer called with
app()->call()(#180) - See 5.0.0 release notes for all other changes
- Projectors should not implement the
Projectorinterface anymore. Instead, they should extend fromSpatie\EventSourcing\EventHandlers\Projectors\Projectorclass. You don't need the use theProjectsEventstrait anymore, as it's already applied on the base class. - The
QueuedProjectorinterface does not exist anymore. If you want to queue a projector you should let it implement the marker interfacelluminate\Contracts\Queue\ShouldQueue. - Reactors should not implement
EventHandleranymore. Instead, they should extend fromSpatie\EventSourcing\EventHandlers\Reactors\Reactor. In previous versions all reactors where called asynchronously via a job. If you want to keep that behavior (in most cases you'll want this), you should also let the reactor implementlluminate\Contracts\Queue\ShouldQueue. - All classes that revolve around the concept of stored events have been moved to the
Spatie\EventSourcing\StoredEventsnamespace. If you are using any of those classes, take a look inside the source code of the package what the new namespace is. - Aggregate roots are now in a dedicated separate namespace
Spatie\EventSourcing\AggregateRoots. You should update all aggregate roots and fake aggregate roots to this namespace. - The
ShouldBeStoredinterface is now an abstract base class. In all your events you should extend it now, instead of implementing it - the
resetmethod has been removed on projectors, useresetStateinstead - the
fakemethod on an aggregate root now accepts a uuid instead of an array of events. Usegivento pass the events you are now passing tofake - the variable used to accept the event in the apply methods on aggregates is required to be named
$event
- Add an
aggregate_versionproperty to thestored_eventstable$table->unsignedInteger('aggregate_version')->nullable(); - Republish the migrations or copy the
create_snapshots_tablemigration - The
StoredEventRepositoryinterface has new methods calledretrieveAllAfterVersionandgetLatestVersionthat you must implement if you have a custom repository - The
StoredEventRepositorynow accepts anaggregateVersionparameter in thepersistandpersistManymethods - The
StoredEventRepositoryhas a newcountAllStartingFrommethod
Nothing changed, expect that where possible property types and short closures are used
The only change in this version is the naming change from laravel-event-projector to laravel-event-sourcing. There are no changes to the API.
To upgrade from v3 of laravel-event-projector you have to perform these steps:
- Merge the
config/event-projector.phpwithvendor/spatie/laravel-event-sourcing/config/event-sourcing.php - Rename
config/event-projector.phptoconfig/event-sourcing.php - Change
laravel-event-projector:v3tolaravel-event-sourcing:v1and runcomposer update - The namespace has changed, so you need to replace
Spatie\EventProjectorbySpatie\EventSourcingin your entire project