dekeysoft / yii2-domain
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-yii2-domain-29
- dev-changed-attributes
- dev-yii2-domain-27
- dev-integrate-flow
- dev-restore-entity
This package is not auto-updated.
Last update: 2022-02-01 13:05:21 UTC
README
Yii2 Domain 是 Yii2 的领域驱动设计模式实现。
包括以下模式的实现
- 仓库
- 实体
- 规范(通过 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服务器