wallsfantasy / event-store-laravel-package
Laravel项目中使用事件存储的包
Requires
- php: ^7.1
- prooph/event-store: ^7.2
- prooph/pdo-event-store: ^1.0
Requires (Dev)
- laravel/framework: ^5.6
- prooph/event-sourcing: ^5.2
This package is not auto-updated.
Last update: 2024-10-02 21:30:52 UTC
README
此包提供了在Laravel项目中利用Prooph事件存储所需的所有工具。
关于如何使用此项目的示例,请参考ProophessorDo Laravel示例。
特性
- 支持开箱即用的PDO事件存储
- 提供用于处理投影的命令
- 将存储库绑定到类名和可选接口
- 支持自定义投影管理器和事件存储解析器
- 支持快照存储
- 添加用于流、投影和快照的迁移
安装
composer require camuthig/laravel-event-store-package
设置
发布配置
php artisan vendor:publish
包含提供者
安装后,包将被Laravel自动发现,不需要更改包含服务提供者的设置。
用法
事件存储
每个事件存储以多种方式绑定。
- 每个存储都绑定到其实现的类
- 默认存储也将绑定到
EventStore接口
此外,还可以通过名称检索每个存储,名称可在配置文件中找到,使用EventStoreManager或EventStore外观。
<?php use Camuthig\EventStore\Package\EventStoreManager; use Prooph\EventStore\EventStore; use Prooph\EventStore\Pdo\MySqlEventStore; class MyController { public function __construct(EventStore $eventStore, MySqlEventStore $mySqlEventStore, EventStoreManager $eventStoreManager) { // The EventStore interface will be bound to the "default" store $eventStore->fetchCategoryNames(null); // Each event store is also bound to the class it is an instance of $mySqlEventStore->fetchCategoryNames(null); // The EventStoreManager is also bound into the application // The default event store can be retrieved from the EventStoreManager $eventStoreManager->store()->fetchCategoryNames(null); // Or you can fetch any store by name $eventStoreManager->store('postgres')->fetchCategoryNames(null); // Or you can work wih the manager by facade \Camuthig\EventStore\Package\Facade\EventStore::store()->fetchCategoryNames(null); } }
存储库
每个存储库将绑定到配置文件中定义的repository_class。此外,您可以提供repository_interface。如果提供,实例也将绑定到该接口,可用于依赖注入。
投影管理器
投影管理器配置并绑定到Artisan应用。该包定义了一系列命令来与投影管理器协同工作,以完成以下任务
- 运行投影
- 删除投影
- 重置投影
- 停止投影
- 显示投影的状态
- 显示投影的事件流位置
- 列出所有可用的投影
要使用这些命令,首先以名称启动投影
php artisan event-store:projection:run users
在投影运行时,您可以删除/重置/停止它
php artisan event-store:projection:reset users
php artisan event-store:projection:delete -w users
php artisan event-store:projection:stop users
配置
插件
全局可用的Event Store插件列表。每个条目将是插件的注册服务ID。应用将为列表中的每个条目调用app()->make(<name>)。
[
App\EventStore\Plugins\MyPlugin::class,
]
元数据丰富器
全局可用的Event Store元数据丰富器列表。每个条目将是插件的注册服务ID。应用将为列表中的每个条目调用app()->make(<name>)。
[
App\EventStore\Enrichers\MyEnricher::class,
]
存储
系统中定义的所有事件存储列表。当前插件支持以下存储开箱即用
- MySQL
- MariaDB
- PostgreSQL
每个事件存储可以配置
- 持久化策略 持久化策略的类名或服务ID
- 批量加载大小 查询应在单个批次中返回的事件数量。默认为1000。
- 事件流表 要使用的事件流表。默认为event_streams。
- 消息工厂 要使用的消息工厂。默认是FCQNMessageFactory。
- 禁用事务处理 一个布尔值,用于关闭事务处理。默认为false。
- 事件发射器 默认是ProophEventActionEmitter。
- 包装事件发射器 默认为true。
- 元数据增强器 要添加到存储中的元数据增强器列表。
- 插件 要添加到存储中的插件列表。
- 。
存储库
所有定义的存储库列表。每个存储库都应该使用名称进行索引。每个存储库都应该定义
- store 要使用的存储库键。有效的值是上面
stores数组中的任何键。 - 存储库接口 一个可选的接口,用于将存储库别名为。这可以用于支持类中的依赖注入。
- 存储库类 存储库类的FQCN或服务ID。
- 聚合类型 此存储库维护的聚合的FQCN或数组映射。
- 聚合转换器 聚合的转换器。默认为\Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator。
- 流名称 流名称。
- 每个聚合一个流 设置为true以实现聚合流策略。默认为false。
投影管理器
所有配置的投影管理器列表。每个管理器都应该定义
- store 存储的名称。mysql、maria_db或postgres之一
- 事件流表 默认为event_streams
- 投影表 默认为projections
- 投影 此管理器中所有投影的列表。
每个投影都应该定义
- 连接 要使用的连接名称。这是一个可选配置。如果没有提供,则默认与存储相同的连接。
- 读取模型 投影读取模型的FQCN或服务ID。这是一个可选值,对于读取模型投影是必要的。
- 投影 投影的FQCN或服务ID。