proophsoftware / prooph-bundle
Symfony 扩展包,用于快速开始使用消息总线、CQRS、事件存储和快照功能
Requires
- php: ^5.5 || ^7.0
- doctrine/doctrine-migrations-bundle: ^1.0
- prooph/event-sourcing: ^4.0
- prooph/event-store: ^6.0
- prooph/event-store-bus-bridge: ^2.0
- prooph/event-store-doctrine-adapter: ^3.0
- prooph/service-bus: ^5.0.2
- prooph/snapshot-doctrine-adapter: ^1.0
- prooph/snapshotter: ^1.0
- proophsoftware/prooph-interop-bundle: ^0.1
- sandrokeil/interop-config: ^0.3.1
- symfony/config: ~2.8 || ~3.0
- symfony/dependency-injection: ^2.8 || ^3.0
- symfony/http-kernel: ^2.8 || ^3.0
Requires (Dev)
- fabpot/php-cs-fixer: ^1.11
- phpunit/phpunit: ^4.8 || ^5.0
Suggests
- proophsoftware/prooph-cli: For Rapid Prototyping, if you want to generate your aggregates, commands, handlers and events.
This package is auto-updated.
Last update: 2024-09-17 01:23:26 UTC
README
弃用
根据用户反馈,我们决定重新开始开发 Symfony 集成。此扩展包使用每个 prooph 组件中提供的 interop-container 意识的工厂。然而,在 Symfony 环境中使用这些工厂与您在其他扩展包中了解的方式不同。如果您正在寻找真正的 Symfony 扩展包,请查看以下链接:
- https://github.com/prooph/event-store-symfony-bundle
- https://github.com/prooph/service-bus-symfony-bundle
概述
这是一个为 prooph 组件提供的 Symfony 扩展包,旨在通过 Symfony Doctrine 扩展包快速启动消息总线、CQRS、事件存储和快照功能。它使用 Doctrine DBAL。还有更多适配器可供使用。
它提供了所有 服务定义和默认配置。这是一个类似于快速入门的扩展包。如果您想在生产环境中使用 prooph 组件,我们建议只使用 prooph-interop-bundle 并根据您的需求配置 prooph 组件。有关 prooph 组件的更多详细信息,请参阅 文档。
为了快速原型设计,我们建议使用我们的 prooph-cli 工具。
可用的服务
prooph.service_bus.command_bus
: 分发命令prooph.service_bus.event_bus
: 分发事件prooph.event_bus.transaction_manager
: 服务总线的事件存储事务管理器prooph.event_bus.event_publisher
: 在事件总线上发布事件prooph.event_store.doctrine_adapter
: 事件存储的 Doctrine 适配器prooph.event_store.snapshot_store
: 事件存储快照适配器prooph.event_store.doctrine_snapshot_adapter
: Doctrine 快照适配器
安装
您可以通过将以下要求添加到您的 composer.json 文件中来通过 composer 安装 proophsoftware/prooph-bundle
:"proophsoftware/prooph-bundle": "^0.1"
最后,请确保在 AppKernel.php
中启用以下扩展包,包括以下内容:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Prooph\InteropBundle\ProophInteropBundle(),
new Prooph\Bundle\ProophBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
);
}
数据库
设置 Doctrine 数据库 迁移 以用于事件存储和快照。此扩展包使用 Doctrine 迁移扩展包。
$ php bin/console doctrine:migrations:generate
使用 prooph Doctrine 事件存储模式助手更新生成的迁移类
class Version20160202155238 extends AbstractMigration { public function up(Schema $schema) { \Prooph\EventStore\Adapter\Doctrine\Schema\EventStoreSchema::createSingleStream($schema, 'event_stream', true); } public function down(Schema $schema) { \Prooph\EventStore\Adapter\Doctrine\Schema\EventStoreSchema::dropStream($schema, 'event_stream'); } }
现在轮到快照表了。
$ php bin/console doctrine:migrations:generate
使用 prooph Doctrine 快照模式助手更新生成的迁移类
class Version20160202160810 extends AbstractMigration { public function up(Schema $schema) { \Prooph\EventStore\Snapshot\Adapter\Doctrine\Schema\SnapshotStoreSchema::create($schema, 'snapshot'); } public function down(Schema $schema) { \Prooph\EventStore\Snapshot\Adapter\Doctrine\Schema\SnapshotStoreSchema::drop($schema, 'snapshot'); } }
现在执行迁移的时间到了
$ php bin/console doctrine:migrations:migrate
示例
您只需定义您的模型(实体、存储库)和命令/路由。您可以在 prooph 组件文档 中找到所有这些内容。以下是来自 proophessor-do 示例应用程序 的 YAML 配置示例。
在 YAML 配置中,您必须使用单引号
'
在 app/config/config.yml
中定义 RegisterUser
的聚合存储库、命令路由和事件路由。
prooph: service_bus: command_bus: router: routes: # list of commands with corresponding command handler 'Prooph\ProophessorDo\Model\User\Command\RegisterUser': 'Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler' event_bus: router: routes: # list of events with a list of projectors 'Prooph\ProophessorDo\Model\User\Event\UserWasRegistered': - 'Prooph\ProophessorDo\Projection\User\UserProjector' event_store: # list of aggregate repositories user_collection: repository_class: 'Prooph\ProophessorDo\Infrastructure\Repository\EventStoreUserCollection' aggregate_type: 'Prooph\ProophessorDo\Model\User\User' aggregate_translator: 'Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator' snapshot_store: 'Prooph\EventStore\Snapshot\SnapshotStore'
添加服务容器工厂。以下是上述示例的相应服务 XML 配置示例,其中包含 container-interop。
<?xml version="1.0" encoding="UTF-8" ?> <container xmlns="https://symfony.ac.cn/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://symfony.ac.cn/schema/dic/services https://symfony.ac.cn/schema/dic/services/services-1.0.xsd"> <services> <service id="Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler.factory" class="Prooph\ProophessorDo\Container\Model\User\RegisterUserHandlerFactory"/> <service id="Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler" class="Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler"> <factory service="Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler.factory" method="__invoke"/> <argument type="service" id="interop_container"/> </service> <service id="Prooph\ProophessorDo\Model\User\UserCollection.factory" class="Prooph\ProophessorDo\Container\Infrastructure\Repository\EventStoreUserCollectionFactory"/> <service id="Prooph\ProophessorDo\Model\User\UserCollection" class="Prooph\ProophessorDo\Model\User\UserCollection"> <factory service="Prooph\ProophessorDo\Model\User\UserCollection.factory" method="__invoke"/> <argument type="service" id="interop_container"/> </service> <service id="Prooph\ProophessorDo\Projection\User\UserProjector.factory" class="Prooph\ProophessorDo\Container\Projection\User\UserProjectorFactory"/> <service id="Prooph\ProophessorDo\Projection\User\UserProjector" class="Prooph\ProophessorDo\Projection\User\UserProjector"> <factory service="Prooph\ProophessorDo\Projection\User\UserProjector.factory" method="__invoke"/> <argument type="service" id="interop_container"/> </service> <service id="Prooph\ProophessorDo\Projection\User\UserFinder.factory" class="Prooph\ProophessorDo\Container\Projection\User\UserFinderFactory"/> <service id="Prooph\ProophessorDo\Projection\User\UserFinder" class="Prooph\ProophessorDo\Projection\User\UserFinder"> <factory service="Prooph\ProophessorDo\Projection\User\UserFinder.factory" method="__invoke"/> <argument type="service" id="interop_container"/> </service> </services> </container>
以下是如何调用 RegisterUser
命令的示例
/* @var $container \Symfony\Component\DependencyInjection\ContainerBuilder */ /* @var $commandBus \Prooph\ServiceBus\CommandBus */ $commandBus = $container->get('prooph.service_bus.command_bus'); $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 \Symfony\Component\DependencyInjection\ContainerBuilder */ $userFinder = $container->get('Prooph\ProophessorDo\Projection\User\UserFinder'); $users = $userFinder->findAll();
支持
- 在prooph-users邮件列表中提问。
- 在https://github.com/proophsoftware/prooph-bundle/issues提交问题。
- 在prooph gitter聊天中打招呼。
贡献
请随意fork并扩展现有插件或添加新插件,并将您的更改作为pull request发送!为了确保代码质量的一致性,请为您的所有更改提供单元测试,并可能更新文档。
许可协议
在New BSD License下发布。