class ValidationRuleParser

Properties

array $implicitAttributes

The implicit attributes.

Methods

__construct(array $data)

Create a new validation rule parser.

explode(array $rules)

Parse the human-friendly rules into a full rules array for the validator.

array
explodeRules(array $rules)

Explode the rules into an array of explicit rules.

array
explodeExplicitRule(mixed $rule, string $attribute)

Explode the explicit rule into an array if necessary.

mixed
prepareRule(mixed $rule, string $attribute)

Prepare the given rule for the Validator.

array
explodeWildcardRules(array $results, string $attribute, array|object|string $rules)

Define a set of rules that apply to each element in an array attribute.

array
explodeWildcardRulesCompilable(array $results, string $attribute, array|object|string $rules)

Explode wildcard rules using the original flatten + regex approach.

array
expandWildcardKeys(string $attribute, array $data)

Expand a wildcard attribute into all matching concrete keys by traversing the data structure directly.

void
traverseWildcardSegments(array $segments, int $index, mixed $data, string $prefix, array $results)

Recursively traverse data segments to expand wildcard keys.

bool
containsCompilableRules(array $rules)

Determine if a rules array contains any CompilableRules at any nesting level.

array
mergeRules(array $results, array|object|string $attribute, array|object|string $rules = [])

Merge additional rules into a given attribute(s).

array
mergeRulesForAttribute(array $results, string $attribute, array|object|string $rules)

Merge additional rules into a given attribute.

static array
parse(array|object|string $rule)

Extract the rule name and parameters from a rule.

static array
parseArrayRule(array $rule)

Parse an array based rule.

static array
parseStringRule(string|Stringable $rule)

Parse a string based rule.

static array
parseParameters(string $rule, string $parameter)

Parse a parameter list.

static bool
ruleIsRegex(string $rule)

Determine if the rule is a regular expression.

static string
normalizeRule(string $rule)

Normalizes a rule so that we can accept short types.

static array
filterConditionalRules(array $rules, array $data = [])

Expand the conditional rules in the given array of rules.

static void
flushState()

Flush all static state.

Details

at line 42
__construct(array $data)

Create a new validation rule parser.

Parameters

array $data

the data being validated

at line 50
stdClass explode(array $rules)

Parse the human-friendly rules into a full rules array for the validator.

Parameters

array $rules

Return Value

stdClass

at line 65
protected array explodeRules(array $rules)

Explode the rules into an array of explicit rules.

Parameters

array $rules

Return Value

array

at line 84
protected array explodeExplicitRule(mixed $rule, string $attribute)

Explode the explicit rule into an array if necessary.

Parameters

mixed $rule
string $attribute

Return Value

array

at line 114
protected mixed prepareRule(mixed $rule, string $attribute)

Prepare the given rule for the Validator.

Parameters

mixed $rule
string $attribute

Return Value

mixed

at line 152
protected array explodeWildcardRules(array $results, string $attribute, array|object|string $rules)

Define a set of rules that apply to each element in an array attribute.

Uses a direct tree walk instead of flattening the entire data array with Arr::dot() and regex matching. This is O(n) in the number of matching keys instead of O(n*m) where m is the total flattened key count. Port of laravel/framework PR #59287.

Parameters

array $results
string $attribute
array|object|string $rules

Return Value

array

at line 191
protected array explodeWildcardRulesCompilable(array $results, string $attribute, array|object|string $rules)

Explode wildcard rules using the original flatten + regex approach.

Used for CompilableRules which need the flattened data context that the tree-walk path doesn't provide.

Parameters

array $results
string $attribute
array|object|string $rules

Return Value

array

at line 293
protected array expandWildcardKeys(string $attribute, array $data)

Expand a wildcard attribute into all matching concrete keys by traversing the data structure directly.

Parameters

string $attribute
array $data

Return Value

array

at line 309
protected void traverseWildcardSegments(array $segments, int $index, mixed $data, string $prefix, array $results)

Recursively traverse data segments to expand wildcard keys.

Parameters

array $segments
int $index
mixed $data
string $prefix
array $results

Return Value

void

at line 341
protected bool containsCompilableRules(array $rules)

Determine if a rules array contains any CompilableRules at any nesting level.

Checks both top-level elements and elements inside nested arrays, so mixed rule arrays like ['nullable', Rule::forEach(...)] are detected.

Parameters

array $rules

Return Value

bool

at line 359
array mergeRules(array $results, array|object|string $attribute, array|object|string $rules = [])

Merge additional rules into a given attribute(s).

Parameters

array $results
array|object|string $attribute
array|object|string $rules

Return Value

array

at line 379
protected array mergeRulesForAttribute(array $results, string $attribute, array|object|string $rules)

Merge additional rules into a given attribute.

Parameters

array $results
string $attribute
array|object|string $rules

Return Value

array

at line 394
static array parse(array|object|string $rule)

Extract the rule name and parameters from a rule.

Parameters

array|object|string $rule

Return Value

array

at line 429
static protected array parseArrayRule(array $rule)

Parse an array based rule.

Parameters

array $rule

Return Value

array

at line 437
static protected array parseStringRule(string|Stringable $rule)

Parse a string based rule.

Parameters

string|Stringable $rule

Return Value

array

at line 457
static protected array parseParameters(string $rule, string $parameter)

Parse a parameter list.

Parameters

string $rule
string $parameter

Return Value

array

at line 465
static protected bool ruleIsRegex(string $rule)

Determine if the rule is a regular expression.

Parameters

string $rule

Return Value

bool

at line 473
static protected string normalizeRule(string $rule)

Normalizes a rule so that we can accept short types.

Parameters

string $rule

Return Value

string

at line 485
static array filterConditionalRules(array $rules, array $data = [])

Expand the conditional rules in the given array of rules.

Parameters

array $rules
array $data

Return Value

array

at line 513
static void flushState()

Flush all static state.

Return Value

void