fix(process): 修复自定义配置 required 不生效
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user