ticaje/m2-command-bus
Composer 安装命令:
composer require ticaje/m2-command-bus
包简介
Module uses Command-Bus design pattern
README 文档
README
This extension intends to create an example of how we can use a different approach to Services in Magento in order to simplify the consumption of such services.
Preface
This extension is a practical example to the Command-bus design pattern within Magento context. Normally, when we have services in our custom solutions, we instantiate those services in our consumer classes and call public methods defined in service contracts.
This approach has various setbacks:
- Stateless nature based service violation.
Very often when creating services we end up jeopardizing services themselves by introducing infrastructure related concerns within a service class. The most commonly example of this violation are:
a) Using session related modules within services. This ties up a service to specific context that is mostly, a web based context. b) Using framework specific managing classes within services. An example could be instantiating Store manager within a service class.
Any of the previous examples bring up the inconvenient of having to modify the service class if we want to run it from a new context like a cli command based application or a Cron component.
- API service contracts violation.
On this regard, there is the possibility of adding a lot of arguments to public signatures in order to comply with service needs. An API is the looking glass of a service to the world, so, the less the arguments its signatures have the more consistent the API will become. The idea is to create a defined by contract object in front of API boundaries to pass values needed by services to its functionality. The answer to this requirement are DTOs.
Installation
You can install this package using composer(the only way i recommend)
composer require ticaje/m2-command-bus
Quick Explanation.
The command bus pattern consists of few components to simplify service consumption and maintenance.
Command
A command is basically a DTO that corresponds to a well defined service contract to provide needed input data to services.
Handler
A handler is the context where the service logic is placed, whether as an external dependency or just the reservoir of the logic itself.
Bus
The bus is what connects Commands to Handlers, it's therefore the facade of services to consumers. The consumer instantiates a bus, instantiates a specific command, sets proper data into it and passes it to bus's public signature, normally it is handle/execute method.
In our case we are gonna use a library called Tactician which offers really useful coverage for Command-bus pattern.
Bibliography
-
https://matthiasnoback.nl/2015/01/responsibilities-of-the-command-bus/
-
https://refactoring.guru/design-patterns/command/php/example
Credits
License
The GNU General Public License (GPLv3). Please see License File for more information.
ticaje/m2-command-bus 适用场景与选型建议
ticaje/m2-command-bus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ticaje/m2-command-bus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ticaje/m2-command-bus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2022-01-11