fix(process): 修复自定义配置 required 不生效

This commit is contained in:
zimoyin
2026-03-11 15:04:11 +08:00
parent f2ff4ae123
commit 8e617d06bc
11 changed files with 49 additions and 17 deletions
+16 -2
View File
@@ -29,7 +29,20 @@ class StepsConfig extends AbstractConfig
} elseif ($override) {
$this->steps = $parsed;
} else {
$this->steps = array_merge(self::defaultSteps(), $parsed);
// 核心逻辑:合并默认步骤 + 自定义步骤,重复 code 以自定义步骤为准
// 1. 将默认步骤转为「code => StepConfig」的关联数组(方便快速查找/覆盖)
$defaultStepsMap = [];
foreach (self::defaultSteps() as $defaultStep) {
$defaultStepsMap[$defaultStep->code] = $defaultStep;
}
// 2. 遍历自定义步骤,覆盖默认步骤中相同 code 的元素
foreach ($parsed as $customStep) {
$defaultStepsMap[$customStep->code] = $customStep;
}
// 3. 转回索引数组(重置键名从0开始),赋值给 $this->steps
$this->steps = array_values($defaultStepsMap);
}
}
@@ -152,12 +165,13 @@ class StepsConfig extends AbstractConfig
*/
private static function createStep(array $step): StepConfig
{
$known = ['code', 'class', 'enabled'];
$known = ['code', 'class', 'enabled', 'required'];
$expand = array_diff_key($step, array_flip($known));
return new StepConfig(
$step['code'],
$step['class'],
$step['enabled'] ?? true,
$step['required'] ?? [],
$expand
);
}