- FormFieldBindingMergeStrategy::nullWinnerBehaviour() and isValidForScalarTargets() encode the per-strategy null-winner matrix (RFC Q7) and the collection-only restriction (RFC V1). - ResolvedBinding/BindingApplicationResult/BindingPassResult readonly DTOs for the binding pipeline. Construction-time validation for trust level. Apply-status derived from result aggregate. Note: the existing enum is named FormFieldBindingMergeStrategy (not MergeStrategy as the prompt sketched). Methods added to it directly. Refs: RFC-WS-6.md §3 (Q4, Q7), §4 (V1) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\FormBuilder\Bindings;
|
|
|
|
use App\Enums\FormBuilder\ApplyStatus;
|
|
|
|
/**
|
|
* RFC-WS-6 §3 (Q4) — aggregate result of one
|
|
* {@see \App\Services\FormBuilder\FormBindingApplicator} pass over a
|
|
* submission. `applyStatus()` is the canonical mapping consumed by
|
|
* `form_submissions.apply_status`.
|
|
*/
|
|
final readonly class BindingPassResult
|
|
{
|
|
/**
|
|
* @param list<BindingApplicationResult> $applications
|
|
*/
|
|
public function __construct(
|
|
public string $formSubmissionId,
|
|
public ?string $provisionedSubjectType,
|
|
public ?string $provisionedSubjectId,
|
|
public array $applications,
|
|
) {}
|
|
|
|
public function applyStatus(): ApplyStatus
|
|
{
|
|
if ($this->applications === []) {
|
|
return ApplyStatus::COMPLETED;
|
|
}
|
|
|
|
$successes = $this->successCount();
|
|
$failures = $this->failureCount();
|
|
|
|
if ($failures === 0) {
|
|
return ApplyStatus::COMPLETED;
|
|
}
|
|
if ($successes === 0) {
|
|
return ApplyStatus::FAILED;
|
|
}
|
|
|
|
return ApplyStatus::PARTIAL;
|
|
}
|
|
|
|
public function successCount(): int
|
|
{
|
|
return count(array_filter($this->applications, fn (BindingApplicationResult $r): bool => $r->success));
|
|
}
|
|
|
|
public function failureCount(): int
|
|
{
|
|
return count(array_filter($this->applications, fn (BindingApplicationResult $r): bool => ! $r->success));
|
|
}
|
|
|
|
/**
|
|
* @return list<BindingApplicationResult>
|
|
*/
|
|
public function failures(): array
|
|
{
|
|
return array_values(array_filter(
|
|
$this->applications,
|
|
fn (BindingApplicationResult $r): bool => ! $r->success,
|
|
));
|
|
}
|
|
}
|