swag-industries/doctrine-domain-events
Composer 安装命令:
composer require swag-industries/doctrine-domain-events
包简介
README 文档
README
This library is design to help you to build your application with a Domain Design Development approach.
It is well integrated with:
- Symfony >= 5.5 (for >=4.4 compatibility, install the version 2.2 of Doctrine domain events)
- ApiPlatform >= 2.1
- Doctrine >= 2.5
- PHP >= 7.4
But you can use it with any PHP project.
Here are some slides that explain how we get there.
Features
Domain Events:
- 🔔 Domain event dispatcher
- ⚡ Injection of the dispatcher in Doctrine entities
- 🔧 Symfony serializer integration
- ⭐ Learn how do more with our cookbooks
Drawbacks
This library is build to allow you to use Doctrine models as Domain model. This has some cost: you can't instantiate domain model by hand anymore. This means that you need a factory for any of the usage of your domain model.
This component provides the implementation for Symfony serializer and Doctrine. For your own
needs you should use the class (service if you use the bundle) Biig\Component\Domain\Model\Instantiator\Instantiator.
Installation
composer require swag-industries/doctrine-domain-events
Basic usage
class YourModel extends DomainModel { public const CREATION = 'creation'; public function __construct() { $this->dispatch(new DomainEvent($this), self::CREATION); } }
/** * @implements DomainRuleInterface<DomainEvent> */ class DomainRule implements DomainRuleInterface { public function on(): string|array { return YourModel::CREATION; // Or YourCustomEvent::class that extends DomainEvent } public function execute(DomainEvent $event) { // Do Something on your model creation } }
As your model needs a dispatcher you need to call the setDispatcher() method any time you create a new instance of your model. To avoid doing this manually you can use the Instantiator that the library provides.
It doesn't use the constructor to add the dispatcher because in PHP you can create objects without the constructor. For instance, that's what Doctrine does.
use Biig\Component\Domain\Model\Instantiator\Instantiator; use Doctrine\ORM\EntityManager; class SomeController { public function index(Instantiator $instantiator, EntityManager $entityManager) { $model = $instantiator->instantiate(YourModel::class); $entityManager->persist($model); $entityManager->flush(); } }
Integration to Symfony
Use the bundle :
<?php // config/bundles.php return [ // ... Biig\Component\Domain\Integration\Symfony\DomainBundle::class => ['all' => true], ];
Learn more about Symfony Integration
Versions
| Version | Status | Documentation | Symfony Version | PHP Version | Misc |
|---|---|---|---|---|---|
| 1.x | Unmaintained | v1 | >= 3.3 && <5 | >= 7.1 | |
| 2.x | Unmaintained | v2 | >= 4.3 | >= 7.4 | |
| 3.x | Unmaintained | [v3][v3-doc] | >= 6.4 | >= 8.1 | See UPGRADE guide |
| 4.x | Latest | [v3][v3-doc] | >= 6.4 | >= 8.1 | See UPGRADE guide |
swag-industries/doctrine-domain-events 适用场景与选型建议
swag-industries/doctrine-domain-events 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.7k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 swag-industries/doctrine-domain-events 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swag-industries/doctrine-domain-events 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-06