prooph / laravel-package
Laravel 包,用于 prooph 组件,可快速开始使用消息总线、CQRS、事件存储和快照
Requires
- php: ^7.1
- illuminate/bus: ^5.0
- illuminate/contracts: ^5.0
- illuminate/support: ^5.0
- prooph/event-sourcing: ^5.0
- prooph/event-store: ^7.0
- prooph/event-store-bus-bridge: ^3.0
- prooph/pdo-event-store: ^1.0
- prooph/pdo-snapshot-store: ^1.1
- prooph/service-bus: ^6.0
- psr/container: ^1.0
- sandrokeil/interop-config: ^2.0
Requires (Dev)
- laravel/framework: ^5.0
- phpunit/phpunit: ^4.8 || ^5.0
- prooph/php-cs-fixer-config: ^0.1.1
- react/promise: ^2.5
- satooshi/php-coveralls: ^1.0
Suggests
- illuminate/database: If you want to use the database migration schema classes for event store and snapshot
- proophsoftware/prooph-cli: For Rapid Prototyping, if you want to generate your aggregates, commands, handlers and events.
Conflicts
- sandrokeil/interop-config: <2.0.1
This package is auto-updated.
Last update: 2024-08-29 03:18:34 UTC
README
概述
这是一个 Laravel 包,用于 prooph 组件,可快速开始使用消息总线、CQRS、事件存储和快照。它使用 prooph/pdo-event-store
事件存储,但也提供了更多适配器。
它提供了所有 服务定义和默认配置。这是一个快速启动包。如果您想在生产环境中使用 prooph 组件,我们建议根据您的需求配置 prooph 组件。请参阅 文档 了解 prooph 组件 的更多详细信息。
为了快速原型设计,我们建议使用我们的 prooph-cli 工具。
可用服务
Prooph\ServiceBus\CommandBus
: 分发命令Prooph\ServiceBus\EventBus
: 分发事件Prooph\ServiceBus\QueryBus
: 允许通过消息总线进行查询Prooph\EventStoreBusBridge\TransactionManager
: 服务总线的事件存储事务管理器Prooph\EventStoreBusBridge\EventPublisher
: 在事件总线上发布事件
可用事件存储
Prooph\EventStore\Pdo\MariaDbEventStore
: MariaDB 事件存储适配器Prooph\EventStore\Pdo\MySqlEventStore
: MySQL 事件存储适配器Prooph\EventStore\Pdo\PostgresEventStore
: PostgreSQL 事件存储适配器
可用外观
CommandBus
: 使用示例: https://github.com/prooph/laravel-package/blob/master/examples/command_bus.phpEventBus
: 使用示例: https://github.com/prooph/laravel-package/blob/master/examples/event_bus.phpQueryBus
: 使用示例: https://github.com/prooph/laravel-package/blob/master/examples/query_bus.php
安装
您可以通过在您的 composer.json 中添加 "prooph/laravel-package": "^0.4"
作为依赖项,通过 Composer 安装 prooph/laravel-package
。
服务提供者
如果您使用的是 Laravel 5.5 或更高版本,则包将自动注册自身。否则,您需要将 Prooph\Package\ProophServiceProvider
添加到您的 提供者 数组中。然后您将能够访问上述服务。
此包具有配置文件,可以根据您的需要进行配置。
部署 prooph 配置文件以添加对 prooph 组件的配置。
$ php artisan vendor:publish
数据库
使用以下命令设置 Event Store 和快照的数据库迁移
$ php artisan make:migration create_event_stream_table
更新类 CreateEventStreamTable
class CreateEventStreamTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { \Prooph\Package\Migration\Schema\EventStoreSchema::createSingleStream('event_stream', true); } /** * Reverse the migrations. * * @return void */ public function down() { \Prooph\Package\Migration\Schema\EventStoreSchema::dropStream('event_stream'); } }
现在更新快照表。
$ php artisan make:migration create_snapshot_table
更新类 CreateSnapshotTable
class CreateSnapshotTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { \Prooph\Package\Migration\Schema\SnapshotSchema::create('snapshot'); } /** * Reverse the migrations. * * @return void */ public function down() { \Prooph\Package\Migration\Schema\SnapshotSchema::drop('snapshot'); } }
现在是执行迁移的时候了
$ php artisan migrate
示例
您只需定义您的模型(实体、仓库)以及命令/路由。以下是从 proophessor-do 示例应用程序 中的示例配置。
在 config/prooph.php
中定义 RegisterUser
的聚合仓库、命令路由和事件路由。
// add the following config in your config/prooph.php under the specific config key return [ 'event_store' => [ // list of aggregate repositories 'user_collection' => [ 'repository_class' => \Prooph\ProophessorDo\Infrastructure\Repository\EventStoreUserCollection::class, 'aggregate_type' => \Prooph\ProophessorDo\Model\User\User::class, 'aggregate_translator' => \Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator::class, 'snapshot_store' => \Prooph\EventStore\Snapshot\SnapshotStore::class, ], ], 'service_bus' => [ 'command_bus' => [ 'router' => [ 'routes' => [ // list of commands with corresponding command handler \Prooph\ProophessorDo\Model\User\Command\RegisterUser::class => \Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler::class, ], ], ], 'event_bus' => [ 'router' => [ 'routes' => [ // list of events with a list of projectors \Prooph\ProophessorDo\Model\User\Event\UserWasRegistered::class => [ \Prooph\ProophessorDo\Projection\User\UserProjector::class ], ], ], ], ], ];
将服务容器工厂添加到 config/dependencies.php
。
// add the following config in your config/dependencies.php after the other factories return [ // your factories // Model \Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler::class => \Prooph\ProophessorDo\Container\Model\User\RegisterUserHandlerFactory::class, \Prooph\ProophessorDo\Model\User\UserCollection::class => \Prooph\ProophessorDo\Container\Infrastructure\Repository\EventStoreUserCollectionFactory::class, // Projections \Prooph\ProophessorDo\Projection\User\UserProjector::class => \Prooph\ProophessorDo\Container\Projection\User\UserProjectorFactory::class, \Prooph\ProophessorDo\Projection\User\UserFinder::class => \Prooph\ProophessorDo\Container\Projection\User\UserFinderFactory::class, ];
以下是如何调用 RegisterUser
命令的示例
/* @var $container \Illuminate\Container\Container */ /* @var $commandBus \Prooph\ServiceBus\CommandBus */ $commandBus = $container->make(Prooph\ServiceBus\CommandBus::class); $command = new \Prooph\ProophessorDo\Model\User\Command\RegisterUser( [ 'user_id' => \Rhumsaa\Uuid\Uuid::uuid4()->toString(), 'name' => 'prooph', 'email' => 'my@domain.com', ] ); $commandBus->dispatch($command);
以下是如何从上面的示例中获取所有用户列表的示例
/* @var $container \Illuminate\Container\Container */ $userFinder = $container->make(Prooph\ProophessorDo\Projection\User\UserFinder::class); $users = $userFinder->findAll();
支持
- 在 Stack Overflow 上使用标签 #prooph 提出问题。
- 在 https://github.com/prooph/laravel-package/issues 上提交问题。
- 在 prooph gitter 聊天室中说声你好。
贡献
请随意分支并扩展现有插件或添加新插件,并将更改后的拉取请求发送给我们!为了建立一致的代码质量,请为您的所有更改提供单元测试,并可能对文档进行适当调整。
许可证
在 New BSD 许可证 下发布。