tjovaisas/delayed-event-bundle
Composer 安装命令:
composer require tjovaisas/delayed-event-bundle
包简介
Bundle to handle post flush doctrine event in an usual event manner
README 文档
README
Symfony bundle to handle post flush doctrine event in an usual event manner
Why ?
Symfony already offers great way to dispatch events to predefined subscribers. This bundle extends that functionality to let listeners receive a dispatched event only after flush has been called. There are a few reasons for that:
- application needs to make external calls only after data been written to the database;
- application needs to publish data to queue only after data been written to the database;
- applications logic requires flushing only in the upper level (e.g. controller or command) while most of the logic lies deep into the services. This helps to avoid having multiple events dispatched from the controllers or commands;
- application needs to make other extra steps only after data been written to the database;
Installation
composer require tjovaisas/delayed-event-bundle
Register the bundle:
Register bundle into config/bundles.php:
return [ //... \Tjovaisas\Bundle\DelayedEventBundle\TjovaisasDelayedEventBundle::class => ['all' => true], ];
Usage
Bundle can be configured either using service's configuration's definition or by using attributes:
- Default
kernel.event_listenertag can be changed totjovaisas.event_listener.post_flushto dispatch message to the given listener after flush occured:
<service class="Namespace\SomeListener" id="namespace.some_listener"> <tag name="tjovaisas.event_listener.post_flush" event="some_event" method="onEvent" priority="1" /> </service>
- Using attributes. Attribute can be defined either on the whole class
#[AsDelayedEventListener(event: 'some_event', method: 'onEvent', priority: 1)] class SomeListener { //... }
or on classes method (only for Symfony ^6.0):
#[AsDelayedEventListener(event: 'some_event')] public function onEvent(): void { //... }
Caviats
There is no easy way to know if an entity already appears in the database after the changes if transaction is being used.
Due to doctrine's default behavior using transactions, first action being used is flush and later on commit.
That means that listener may get event with data that already has database generated fields (e.g. id), but still may not be 100% in the database.
Transactions are being sealed only after commit has been called and if this action fails, changes will not appear in the database and listener wouldn't know that.
Semantic versioning
This bundle follows semantic versioning.
Public API of this bundle (in other words, you should only use these features if you want to easily update to new versions):
- only services that are not marked as
public="false"; - only classes, interfaces and class methods that are marked with
@api; - console commands;
- supported DIC tags.
For example, if only class method is marked with @api, you should not extend that class, as constructor
could change in any release.
See Symfony BC rules for basic information
about what can be changed and what not in the API. Keep in mind, that in this bundle everything is
@internal by default.
Running tests
composer update
composer test
Contributing
Feel free to create issues and give pull requests.
You can check code style issues using this command:
composer analyze
tjovaisas/delayed-event-bundle 适用场景与选型建议
tjovaisas/delayed-event-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.2k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「event」 「doctrine」 「flush」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tjovaisas/delayed-event-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tjovaisas/delayed-event-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tjovaisas/delayed-event-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Symfony bundle for broadway/broadway.
Make pimcore migration simple
Bundle Symfony DaplosBundle
Plugins for Tactician commands using Doctrine, like wrapping every command in a transaction
This is an Event Emitter equivalent to Node.js' Event Emitter.
统计信息
- 总下载量: 3.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-06