Download the PHP package veasin/ff-ddd without Composer
On this page you can find all versions of the php package veasin/ff-ddd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download veasin/ff-ddd
More information about veasin/ff-ddd
Files in veasin/ff-ddd
Package ff-ddd
Short Description DDD modeling layer: concept-config driven, separation of abstraction and data operations, built on the veasin/ff functional framework
License LGPL-3.0-or-later
Homepage https://github.com/veasin/ff-ddd
Informations about the package ff-ddd
veasin/ff-ddd
基于 veasin/ff 函数式框架的 DDD 业务建模层。
概念配置驱动:抽象与数据操作分离 —— then 之前只构建概念配置,then 触发才执行数据操作。
安装
veasin/ff 为依赖项,框架函数(如 ff\db、ff\container)通过 composer 的 autoload.files 自动加载。
核心概念
| 术语 | 说明 |
|---|---|
| 概念 | 领域模型最小单元,由 ddd::define() 定义,概念名全小写 / 分隔,如 corp/user |
| 集合 | 概念的一组实例,可被范围方法分割,ddd::collection(name) 开链 |
| 单体 | 集合经 id()/create() 缩小到的唯一元素,ddd::entity(name) 开链 |
| 范围 | 对集合的筛选条件,链上每一步都在叠加 |
| 关系 | 概念间的关联(从属导航),触发根转化 + 范围转换 |
| 配置 | 概念的全部定义,then 前链式操作的最终产物 |
铁律
- 抽象与数据操作分离(
then前只构建配置) - 集合 → 范围方法 → 新集合;单体 → 关系方法 → 集合/单体
- 一切显式,无自动推导(概念必须
define)
配置结构
ddd::define(name, $colCfg, $entCfg) 将集合与单体配置分离为第二、三参数,各自独立归一化、独立存储,不合并。
子类型
集合配置(colConfig,第二参数)
单体配置(entConfig,第三参数)
字段归属
| 字段 | colConfig | entConfig | 说明 |
|---|---|---|---|
source |
✅ | ✅ | 实体构造时 ent→col fallback |
defs |
✅ | ❌ | 集合专属 |
relations |
❌ | ✅ | 单体专属 |
uniques |
✅ | ✅ | 实体构造时 ent→col fallback |
mutators |
✅ | ✅ | 实体构造时 ent→col fallback |
with |
✅ | ✅ | 独立存储不合并;读取时整数组 ent→col fallback |
order |
✅ | ❌ | 仅集合配置持有 |
base |
✅ | ✅ | 同类型继承(col→col, ent→ent) |
配置分离强制规则:colConfig 不含
relations/create;entConfig 不含defs/entity。normalize()阶段强制执行(传入即剥离)。
视图构造 fallback
实体构造时,最终配置 = entConfig 为基底,以下共享字段若 entConfig 不存在则从 colConfig 回退读取:
共享字段仅 source、uniques、mutators 三项。order 不属于共享字段——实体没有默认排序。
with 为特例:独立存储、不做构造期合并,仅在读取时由 concept 整数组 fallback(ent.with ?? col.with)。entity 定义了 with 则整数组遮蔽 col(不按段回退);未定义则读 col 的 with。
base 继承
base 仅同类型继承(colConfig→父 colConfig,entConfig→父 entConfig),不跨类型:
- 父项某 key 为数组(
defs/relations)则逐项合并,子优先;子值为null删除父对应项 - 非数组字段直接覆盖(
with属此类——整键替换,不做段级合并) base继承关系在normalize()阶段解析展开,展开后base字段被移除
正常化(normalize)拆分
集合和单体各自独立归一化:
normalizeCol:defs→[],mutators→[],with→[],scopes→[],pending→[],refs→[];uniques→['id'];剥离relations/createnormalizeEnt:relations→[],scopes→[],pending→[],refs→[];剥离defs/entity/order。with不设默认值——未定义则不存,从而保证 concept 读取时能 fallback 到 col
with 查询级联
with 用于"查询主概念时同时 JOIN 关联概念、带出额外字段"。配置在集合(默认),单体可额外定义(整数组遮蔽集合)。
返回形态:主表不设别名(字段用限定符限定:表带别名用别名、否则用表名),join 表别名 = 配置 key。fields 为字段列表时直接输出 别名.字段(不设别名);fields 为 输出键 => 字段 时重命名输出。join 生效时,ON / WHERE / ORDER BY 的字段一律用主表限定符限定(防同名列歧义):
trigger 签名(末尾参数 = with 段名):
list(array $options = [], ?string $with = 'list')——null禁用、其他字符串读自定义段get(array $options = [], ?string $with = 'get')—— 同上
规则:
with生效时options['select']被忽略(带出字段由 with 生成)- 分页
list()的 count 始终单表单表,不 join $with === null回退普通单表查询- join 目标概念无数据源或 via 为空 →
DomainException(铁律 #5 构建错误致命化)
自定义 Trigger 扩展
业务方法(如 launch()、toggleSkip())属于"找到实体后的数据操作",应放在 Trigger 上。通过 lv0 配置注入 trigger 即可,不必绕三层继承:
同样支持集合 Trigger 扩展(继承 trigger\collection)。若需自定义 Entity(如有额外导航方法),配置 entity 指定 fork 目标:
快速开始
IDE 辅助
生成 PhpStorm 元数据(override / expectedArguments / registerArgumentsSet),
以及 IDE 桩类(_ddd 命名空间,@method 标注 defs / relations / 自定义方法)。
支持 lv1 class 反射 + base 继承链合并。collection() 和 entity() 各自独立提示列表。