feat(form-builder): MergeStrategy enum methods + binding value objects (WS-6)
- 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>
This commit is contained in:
61
api/app/FormBuilder/Bindings/BindingApplicationResult.php
Normal file
61
api/app/FormBuilder/Bindings/BindingApplicationResult.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\FormBuilder\Bindings;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* RFC-WS-6 §3 (Q4) — the result of applying a single resolved binding
|
||||
* to its target. Sealed via two named constructors so consumers can't
|
||||
* synthesise impossible states (success-with-exception, etc.).
|
||||
*/
|
||||
final readonly class BindingApplicationResult
|
||||
{
|
||||
private function __construct(
|
||||
public string $bindingId,
|
||||
public string $targetEntity,
|
||||
public string $targetAttribute,
|
||||
public bool $success,
|
||||
public mixed $oldValue,
|
||||
public mixed $newValue,
|
||||
public ?string $exceptionClass = null,
|
||||
public ?string $exceptionMessage = null,
|
||||
) {}
|
||||
|
||||
public static function succeeded(
|
||||
string $bindingId,
|
||||
string $targetEntity,
|
||||
string $targetAttribute,
|
||||
mixed $oldValue,
|
||||
mixed $newValue,
|
||||
): self {
|
||||
return new self(
|
||||
bindingId: $bindingId,
|
||||
targetEntity: $targetEntity,
|
||||
targetAttribute: $targetAttribute,
|
||||
success: true,
|
||||
oldValue: $oldValue,
|
||||
newValue: $newValue,
|
||||
);
|
||||
}
|
||||
|
||||
public static function failed(
|
||||
string $bindingId,
|
||||
string $targetEntity,
|
||||
string $targetAttribute,
|
||||
Throwable $e,
|
||||
): self {
|
||||
return new self(
|
||||
bindingId: $bindingId,
|
||||
targetEntity: $targetEntity,
|
||||
targetAttribute: $targetAttribute,
|
||||
success: false,
|
||||
oldValue: null,
|
||||
newValue: null,
|
||||
exceptionClass: $e::class,
|
||||
exceptionMessage: $e->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user