desmart / laravel-event-sourcing
DeSmart Event Sourcing 包的 Laravel 绑定
1.0.0
2016-05-25 07:01 UTC
Requires
- php: >=5.6.0
- desmart/event-sourcing: 1.*
- illuminate/console: 5.2.*
- illuminate/contracts: 5.2.*
- illuminate/database: 5.2.*
- illuminate/support: 5.2.*
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is not auto-updated.
Last update: 2024-09-14 19:31:08 UTC
README
简单 Laravel 事件溯源机制实现。
注意:此包仍在开发中,可能会出现一些破坏性更改。
该包实现了 Laravel 框架中的事件溯源概念。包包含两个主要元素:类似数据库的事件存储实现和投影管理器。
事件存储是一个只追加存储,用于存储事件。投影管理器允许注册投影,并通过生成的事件流来更新它们。
安装
要使用 Composer 安装此包,只需运行以下命令
composer require desmart/laravel-event-sourcing
为了使用提供的事件存储实现,请在您的 config/app.php
文件中注册服务提供者
'providers' => [ // ... DeSmart\EventSourcing\Laravel\EventStore\ServiceProvider::class, ]
为了使用投影管理器,请在您的 config/app.php
文件中注册服务提供者
'providers' => [ // ... DeSmart\EventSourcing\Laravel\Projections\ServiceProvider::class, ]
注册服务提供者后,运行 artisan 命令以发布配置文件
php artisan vendor:publish
配置
此包添加了两个配置文件:event-store.php
和 read-model.php
。
event-store.php
在此处您可以配置
- 将使用哪个连接连接到您的事件存储
- 将使用哪个事件的有效载荷序列化程序
return [ /* |------------------------------------------------------------------------------------- | Database Connection For Event Store |------------------------------------------------------------------------------------- | | Specify which database connection should be used for storing events in events store. | All database connections can be found in config/database.php configuration file. | */ 'connection' => null, /* |------------------------------------------------------------------------------------- | Event Store Payload Serializer |------------------------------------------------------------------------------------- | | Serializer used for serializing/deserializing event and it's payload. | | Payload is usually of array type. It is sufficient to store payload in | JSON format. | | Supported serializers: | - 'JsonSerializer' -> use for event store that does not have automatic json serialization/deserialization, like mysql databases | - 'ArraySerializer -> use for event store that has automatic json serialization/deserialization, like mongodb databases | */ 'serializer' => \DeSmart\EventSourcing\Laravel\EventStore\Serializers\JsonSerializer::class ];
read-model.php
在此处您可以注册所有应通过事件流通知的投影
return [ /* |-------------------------------------------------------------------------- | Read Model Projections |-------------------------------------------------------------------------- | | Array of projection classes. | | These projections will be notified about saved stream of events and they | can react with read model updates. | */ 'projections' => [] ];
事件存储实现
此包的事件存储实现已在 MySQL 数据库、MongoDB 数据库以及两者的混合中成功使用/测试过:一个数据库作为事件存储,另一个存储投影。
所需的事件存储结构(尽管允许不同的列类型)可以在 这里 找到。
许可协议
此包在 MIT 许可协议(MIT)下发布。请参阅 LICENSE 了解更多详情。
示例用法
例如,要使用事件存储以及项目管理器,请查看 example/
目录。
此外,此包还提供 artisan 命令用于重建所有投影
php artisan projections:rebuild