andy-thorne / domain-events-bundle
Doctrine ODM 和 ORM 的领域事件
2.0.0
2022-01-11 12:46 UTC
Requires
- php: ^8.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/messenger: ^5.4|^6.0
- symfony/uid: ^5.4|^6.0
- symfony/yaml: ^5.4|^6.0
Requires (Dev)
- ext-mongo: *
- ext-mongodb: *
- alcaeus/mongo-php-adapter: ^1.2
- dama/doctrine-test-bundle: ^6.3
- doctrine/doctrine-bundle: ^2.0
- doctrine/mongodb-odm-bundle: ^4.0
- doctrine/orm: ^2.0
- escapestudios/symfony2-coding-standard: ^3.11
- friendsofphp/php-cs-fixer: ^3.0
- mongodb/mongodb: ^1.8
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.1
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-mongo: For use with Doctrine ODM
- ext-mongodb: For use with Doctrine ODM
- alcaeus/mongo-php-adapter: For use with Doctrine ODM
- doctrine/mongodb-odm-bundle: For use with Doctrine ODM
- doctrine/orm-pack: For use with Doctrine ORM
- mongodb/mongodb: For use with Doctrine ODM
This package is auto-updated.
Last update: 2024-09-11 18:12:37 UTC
README
此扩展包通过MessageBus在 doctrine 事件上添加领域事件分派。
安装
composer require andy-thorne/domain-events-bundle
配置
# Defaults domain_events: orm: true odm: false bus: domain_event.bus transport: async_domain_events configure_routing: true # Auto-configures messenger routing for DomainEventInterfaces to route to the configured transport framework: messenger: transports: async_domain_events: "%env(ASYNC_MESSENGER_TRANSPORT_DSN)%"
该扩展包还会根据您的 domain_events
配置来配置这些 messenger 设置。如果您已经配置了总线,您将需要指定 framework.messenger.default_bus
。
# The bundle also configures your framework: messenger: # Set up a bus that will allows no handlers buses: <domain_events.bus>: default_middleware: allow_no_handlers # Route all domain events to the domain event transport if configure_routing is true (default) routing: 'AndyThorne\Components\DomainEventsBundle\Events\DomainEventInterface': <domain_events.transport>
消息总线
领域事件使用应用的 MessageBus 来传输领域事件。默认的 Messenger 组件配置为同步,并为每个消息至少定义一个处理器。为了让领域事件正常工作,我们需要配置异步 MessageBus 并允许它没有处理器
为什么异步?
领域事件在 doctrine postFlush 生命周期事件中分派