class Factory implements Factory

Properties

protected PresenceVerifierInterface|null $verifier

The Presence Verifier implementation.

protected Closure|string> $extensions

All of the custom validator extensions.

protected Closure|string> $implicitExtensions

All of the custom implicit validator extensions.

protected Closure|string> $dependentExtensions

All of the custom dependent validator extensions.

protected Closure|string> $replacers

All of the custom validator message replacers.

protected array<string, string> $fallbackMessages

All of the fallback messages for custom rules.

protected bool $excludeUnvalidatedArrayKeys

Indicates that unvalidated array keys should be excluded, even if the parent array was validated.

protected Closure|null $resolver

The Validator resolver instance.

Methods

__construct(Translator $translator, Container|null $container = null)

Create a new Validator factory instance.

make(array $data, array $rules, array $messages = [], array $attributes = [])

Create a new Validator instance.

array
validate(array $data, array $rules, array $messages = [], array $attributes = [])

Validate the given data against the provided rules.

resolve(array $data, array $rules, array $messages, array $attributes)

Resolve a new Validator instance.

void
addExtensions(Validator $validator)

Add the extensions to a validator instance.

void
extend(string $rule, Closure|string $extension, string|null $message = null)

Register a custom validator extension.

void
extendImplicit(string $rule, Closure|string $extension, string|null $message = null)

Register a custom implicit validator extension.

void
extendDependent(string $rule, Closure|string $extension, string|null $message = null)

Register a custom dependent validator extension.

void
replacer(string $rule, Closure|string $replacer)

Register a custom validator message replacer.

void
includeUnvalidatedArrayKeys()

Indicate that unvalidated array keys should be included in validated data when the parent array is validated.

void
excludeUnvalidatedArrayKeys()

Indicate that unvalidated array keys should be excluded from the validated data, even if the parent array was validated.

void
fakeDnsLookups(bool $value = true)

Fake the DNS lookups performed by validation rules so they always succeed.

void
resolver(Closure $resolver)

Set the Validator instance resolver.

getTranslator()

Get the Translator implementation.

getPresenceVerifier()

Get the Presence Verifier implementation.

void
setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Container|null
getContainer()

Get the container instance used by the validation factory.

setContainer(Container $container)

Set the container instance used by the validation factory.

Details

at line 71
__construct(Translator $translator, Container|null $container = null)

Create a new Validator factory instance.

Parameters

Translator $translator

the Translator implementation

Container|null $container

the IoC container instance

at line 80
Validator make(array $data, array $rules, array $messages = [], array $attributes = [])

Create a new Validator instance.

Parameters

array $data
array $rules
array $messages
array $attributes

Return Value

Validator

at line 115
array validate(array $data, array $rules, array $messages = [], array $attributes = [])

Validate the given data against the provided rules.

Parameters

array $data
array $rules
array $messages
array $attributes

Return Value

array

Exceptions

ValidationException

at line 123
protected Validator resolve(array $data, array $rules, array $messages, array $attributes)

Resolve a new Validator instance.

Parameters

array $data
array $rules
array $messages
array $attributes

Return Value

Validator

at line 135
protected void addExtensions(Validator $validator)

Add the extensions to a validator instance.

Parameters

Validator $validator

Return Value

void

at line 157
void extend(string $rule, Closure|string $extension, string|null $message = null)

Register a custom validator extension.

Boot-only. Request-time registration persists for the worker lifetime and exposes the extension to validators built by every concurrent request.

Parameters

string $rule
Closure|string $extension
string|null $message

Return Value

void

at line 172
void extendImplicit(string $rule, Closure|string $extension, string|null $message = null)

Register a custom implicit validator extension.

Boot-only. Request-time registration persists for the worker lifetime and exposes the extension to validators built by every concurrent request.

Parameters

string $rule
Closure|string $extension
string|null $message

Return Value

void

at line 187
void extendDependent(string $rule, Closure|string $extension, string|null $message = null)

Register a custom dependent validator extension.

Boot-only. Request-time registration persists for the worker lifetime and exposes the extension to validators built by every concurrent request.

Parameters

string $rule
Closure|string $extension
string|null $message

Return Value

void

at line 202
void replacer(string $rule, Closure|string $replacer)

Register a custom validator message replacer.

Boot-only. Request-time registration persists for the worker lifetime and exposes the message replacer to validators built by every concurrent request.

Parameters

string $rule
Closure|string $replacer

Return Value

void

at line 213
void includeUnvalidatedArrayKeys()

Indicate that unvalidated array keys should be included in validated data when the parent array is validated.

Boot-only. Request-time mutation persists for the worker lifetime and can change validated-data shape for validators built by concurrent requests.

Return Value

void

at line 224
void excludeUnvalidatedArrayKeys()

Indicate that unvalidated array keys should be excluded from the validated data, even if the parent array was validated.

Boot-only. Request-time mutation persists for the worker lifetime and can change validated-data shape for validators built by concurrent requests.

Return Value

void

at line 235
void fakeDnsLookups(bool $value = true)

Fake the DNS lookups performed by validation rules so they always succeed.

Tests only. The setting persists for the worker lifetime; failing to reset it through Validator::flushState() can make later tests bypass real DNS validation.

Parameters

bool $value

Return Value

void

at line 246
void resolver(Closure $resolver)

Set the Validator instance resolver.

Boot-only. Request-time mutation persists for the worker lifetime and can change the Validator class used by concurrent builds.

Parameters

Closure $resolver

Return Value

void

at line 254
Translator getTranslator()

Get the Translator implementation.

Return Value

Translator

at line 262
PresenceVerifierInterface|null getPresenceVerifier()

Get the Presence Verifier implementation.

Return Value

PresenceVerifierInterface|null

at line 273
void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Boot-only. Request-time mutation persists for the worker lifetime and can route concurrent exists and unique checks through the wrong verifier.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

at line 281
Container|null getContainer()

Get the container instance used by the validation factory.

Return Value

Container|null

at line 293
Factory setContainer(Container $container)

Set the container instance used by the validation factory.

Tests only. Swaps the container on the singleton validation Factory; per-request use races across coroutines and breaks every concurrent validator build.

Parameters

Container $container

Return Value

Factory