定制 tjovaisas/delayed-event-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Latest Version on Packagist Software License PHPUnit Total Downloads

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_listener tag can be changed to tjovaisas.event_listener.post_flush to 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 tjovaisas/delayed-event-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-06