php-kitchen / yii2-domain
Yii2 的领域驱动设计(DDD)关键概念实现。
v0.0.35
2020-03-05 20:24 UTC
Requires
- php: ^7.1
- php-kitchen/yii2-di: ^0.1
- yiisoft/yii2: ^2.0
Requires (Dev)
- php-kitchen/code-specs: ^4.0
- phpunit/phpunit: ^6.5
- satooshi/php-coveralls: ^1.0
Suggests
- yii2tech/ar-softdelete: Needed to support 'Recoverable' functionality.
- dev-master
- 0.0.x-dev
- v0.0.35
- v0.0.34
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
- 0.0.18
- 0.0.17
- 0.0.16
- 0.0.15
- 0.0.14
- 0.0.13
- 0.0.12
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- 0.0.0
- dev-task/35-decouple-actions-classes
- dev-yii2-domain-17
- dev-integrate-flow
This package is auto-updated.
Last update: 2024-09-16 02:48:41 UTC
README
Yii2 Domain 是为 Yii2 实现的领域驱动设计(DDD)模式。
包括以下模式的实现
- 存储库
- 实体
- 规范(通过 ActiveQuery 的非常粗略的实现)
- 策略
需求
PHP >= 7.1
是必需的。
入门
运行以下命令将 Yii2 Domain 添加到项目的 composer.json
文件中。有关特定版本,请参阅 Packagist。
composer require php-kitchen/yii2-domain
或者您可以从以下位置复制此库:
有关更多信息和使用指南,请访问 项目文档
概述
此库的目的是将领域驱动设计(DDD)原则引入 Yii2 项目,并解决具有中等和大型领域区域的域层在应用程序中的 ActiveRecord 问题。
每个模型都表示为一个独立的目录,其中包含存储库、实体、记录和查询类。所有这些类都表示域模型。
典型模型(以用户模型为例)的目录结构
user/ contains all of the classes that represents domain model
UserRepository model repository
UserEntity model entity(represents domain entity - not the DB table that containd entity information)
UserRecord DB record that contains entity information
ProfileRecord DB record with additional information thta also a part of the UserEntity.
UserQuery query class of model e.g. - specification of the entity
代码示例
简单搜索和存储
$repository = new UserRepository(); $entity = $repository->findOneWithPk(1); // do some manipulations with entity $repository->validateAndSave($entity);
复杂条件搜索和删除
$repository = new UserRepository(); $entity = $repository->find() ->active() ->withoutEmail() ->one(); // do some manipulations with entity $repository->delete($entity);
注意
此库旨在解决 Yii 2 的 ActiveRecord 问题。如果您正在启动一个新项目并寻找一个可以构建良好架构的解决方案,则不要使用此库 - 您需要一个允许您构建高质量解决方案的良好框架,而 Yii 2 并不是允许您构建高质量架构和实现丰富域层的框架。
"Yii2Domain" 库是一个支架,旨在解决由 ActiveRecord 在现有项目中引起的域层问题。在新项目中构建域层的解决方案并不多。
- Spot ORM
- Symfony + Doctrine(首选解决方案)
- Eloquent ORM(如果您喜欢 Laravel 且不使用企业应用程序)
贡献
如果您有任何问题,建议改进或只是想与社区和开发者交谈,请加入我们的 Discord 服务器https://discord.gg/Ez5VZhC