trait PlanExecutor

Execute compiled AttributePlans against validation data.

Architecture overview

Hypervel's validation uses compiled execution with a delegated subclass path:

  1. Rules are compiled into AttributePlans by RuleCompiler — each rule becomes either an InlineCheck (fast, match-dispatched) or a DelegatedCheck (calls the existing validate*() method). Plans are cached worker-lifetime by RulePlanCache for Swoole performance.

  2. Safe first-position exclusions are resolved before execution, and wildcard database-presence candidates are queried in ordered groups. Unknown values remain on the ordinary verifier path.

  3. The exact Validator executes optimized plans through a branch-free loop. Subclasses use a Laravel-shaped loop over delegated checks so their validation and stopping hooks remain authoritative.

Maintenance notes

  • Adding a new inline-eligible rule requires review in 4 places: CheckType (enum case + ruleName), RuleCompiler::tryInline(), executeInline() below, and canPreflightInline(). Omitting preflight support is correctness-safe but prevents presence batching across that rule.
  • DelegatedChecks require zero changes — they call validate*() directly.
  • executeInline() arms must match the exact behavior of their corresponding validate*() methods in ValidatesAttributes. When an upstream method changes, the inline arm must be updated to match.

Mixed into Validator so it can call existing helpers on ValidatesAttributes (sizeOf, isValidEmail, compareDates, etc.) and access validator state ($this->data, $this->rules, $this->currentRule, etc.).

Methods

void
executeCompiledPlans(array $compiledPlans, array $preExcludedAttributes)

Execute all compiled plans against the validation data.

void
executeDelegatedPlans(array $compiledPlans)

Execute all-delegated plans for a Validator subclass.

bool
shouldSkipNonImplicitCheck(AttributePlan $plan, mixed $value, bool $exists)

Determine if a non-implicit check should be skipped.

bool
shouldFailInvalidUpload(string $attribute, mixed $value)

Determine if an invalid upload should fail before rule execution.

bool
canPreflightInline(InlineCheck $check, mixed $value)

Determine if an inline check is safe to repeat during presence preflight.

bool
executeInline(InlineCheck $check, mixed $value, string $attribute)

Execute an inline check against a value.

Details

at line 64
protected void executeCompiledPlans(array $compiledPlans, array $preExcludedAttributes)

Execute all compiled plans against the validation data.

Per-check fresh reads of $value and $exists match validateAttribute()'s per-rule getValue() call.

Parameters

array $compiledPlans
array $preExcludedAttributes

Return Value

void

at line 141
protected void executeDelegatedPlans(array $compiledPlans)

Execute all-delegated plans for a Validator subclass.

Parameters

array $compiledPlans

Return Value

void

at line 171
protected bool shouldSkipNonImplicitCheck(AttributePlan $plan, mixed $value, bool $exists)

Determine if a non-implicit check should be skipped.

Parameters

AttributePlan $plan
mixed $value
bool $exists

Return Value

bool

at line 181
protected bool shouldFailInvalidUpload(string $attribute, mixed $value)

Determine if an invalid upload should fail before rule execution.

Parameters

string $attribute
mixed $value

Return Value

bool

at line 191
protected bool canPreflightInline(InlineCheck $check, mixed $value)

Determine if an inline check is safe to repeat during presence preflight.

Parameters

InlineCheck $check
mixed $value

Return Value

bool

at line 256
protected bool executeInline(InlineCheck $check, mixed $value, string $attribute)

Execute an inline check against a value.

Dispatches via exhaustive match over CheckType — no default arm. Adding a CheckType case without a handler here fails PHPStan and throws UnhandledMatchError at runtime. Silent passes are impossible.

Each arm replicates the exact logic of the corresponding validate*() method in ValidatesAttributes, but without parameter parsing, attribute context lookups, or dynamic method dispatch.

Parameters

InlineCheck $check
mixed $value
string $attribute

Return Value

bool