Per-purpose schema validation composes a PurposeGuardProvider returning a list of guards. Errors collected (not first-fail) so the builder UI surfaces every issue per save. ConditionalRequirement composes higher- order without proliferating one-off classes. RequiresIdentityKeyBinding checks the is_identity_key flag specifically; the binding-existence check is handled additively by the existing assertRequiredBindingsPresent in FormSchemaService. SchemaHasLinkedEvent checks owner_type='event' + owner_id (FormSchema uses polymorphic owner; there is no direct event_id column). i18n messages live in lang/nl/form_builder_publish_guards.php. Refs: RFC-WS-6.md §3 (Q13), §4 (V1, V3) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\FormBuilder\Publishing;
|
|
|
|
/**
|
|
* RFC-WS-6 §3 (Q13) — outcome of evaluating a single {@see PublishGuard}.
|
|
* Sealed via two named constructors: callers cannot construct
|
|
* inconsistent states (passed-with-message, etc.).
|
|
*/
|
|
final readonly class PublishGuardResult
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
private function __construct(
|
|
public string $guardCode,
|
|
public bool $passed,
|
|
public ?string $messageKey = null,
|
|
public ?string $offendingFormFieldId = null,
|
|
public array $context = [],
|
|
) {}
|
|
|
|
public static function passed(string $guardCode): self
|
|
{
|
|
return new self(guardCode: $guardCode, passed: true);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
public static function failed(
|
|
string $guardCode,
|
|
string $messageKey,
|
|
?string $offendingFormFieldId = null,
|
|
array $context = [],
|
|
): self {
|
|
return new self(
|
|
guardCode: $guardCode,
|
|
passed: false,
|
|
messageKey: $messageKey,
|
|
offendingFormFieldId: $offendingFormFieldId,
|
|
context: $context,
|
|
);
|
|
}
|
|
}
|