class Validator implements Validator (View source)

Methods

void
__construct(TranslatorInterface $translator, array $data, array $rules, array $messages = array(), array $customAttributes = array())

Create a new Validator instance.

array
parseData(array $data)

Parse the data array.

$this
after(callable|string $callback)

After an after validation callback.

void
sometimes(string $attribute, string|array $rules, callable $callback)

Add conditions to a given field based on a Closure.

void
each(string $attribute, string|array $rules)

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

array
extractValuesForWildcards(array $data, string $attribute)

Get all of the exact attribute values for a given wildcard attribute.

$this
mergeRules(string $attribute, string|array $rules = array())

Merge additional rules into a given attribute(s).

bool
passes()

Determine if the data passes the validation rules.

bool
fails()

Determine if the data fails the validation rules.

void
validate()

Run the validator's rules against its data.

array
valid()

Returns the data which was valid.

array
invalid()

Returns the data which was invalid.

string
guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

bool
isAValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

string
getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

array
attributes()

Get all attributes.

bool
hasAttribute(string $attribute)

Checks if an attribute exists.

bool
hasRule(string $attribute, string|array $rules)

Determine if the given attribute has a rule in the given set.

array
getExtensions()

Get the array of custom validator extensions.

void
addExtensions(array $extensions)

Register an array of custom validator extensions.

void
addImplicitExtensions(array $extensions)

Register an array of custom implicit validator extensions.

void
addExtension(string $rule, Closure|string $extension)

Register a custom validator extension.

void
addImplicitExtension(string $rule, Closure|string $extension)

Register a custom implicit validator extension.

array
getReplacers()

Get the array of custom validator message replacers.

void
addReplacers(array $replacers)

Register an array of custom validator message replacers.

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

Register a custom validator message replacer.

array
getData()

Get the data under validation.

$this
setData(array $data)

Set the data under validation.

array
getRules()

Get the validation rules.

$this
setRules(array $rules)

Set the validation rules.

$this
setAttributeNames(array $attributes)

Set the custom attributes on the validator.

$this
setValueNames(array $values)

Set the custom values on the validator.

getPresenceVerifier()

Get the Presence Verifier implementation.

void
setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

TranslatorInterface
getTranslator()

Get the Translator implementation.

void
setTranslator(TranslatorInterface $translator)

Set the Translator implementation.

array
getCustomMessages()

Get the custom messages for the validator.

void
setCustomMessages(array $messages)

Set the custom messages for the validator.

array
getCustomAttributes()

Get the custom attributes used by the validator.

$this
addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

array
getCustomValues()

Get the custom values for the validator.

$this
addCustomValues(array $customValues)

Add the custom values for the validator.

array
getFallbackMessages()

Get the fallback messages for the validator.

void
setFallbackMessages(array $messages)

Set the fallback messages for the validator.

array
failed()

Get the failed validation rules.

messages()

Get the message container for the validator.

errors()

An alternative more semantic shortcut to the message container.

getMessageBag()

Get the messages for the instance.

void
setContainer(Container $container)

Set the IoC container instance.

mixed
__call(string $method, array $parameters)

Handle dynamic calls to class methods.

Details

at line line 194
void __construct(TranslatorInterface $translator, array $data, array $rules, array $messages = array(), array $customAttributes = array())

Create a new Validator instance.

Parameters

TranslatorInterface $translator
array $data
array $rules
array $messages
array $customAttributes

Return Value

void

at line line 212
array parseData(array $data)

Parse the data array.

Parameters

array $data

Return Value

array

at line line 264
$this after(callable|string $callback)

After an after validation callback.

Parameters

callable|string $callback

Return Value

$this

at line line 281
void sometimes(string $attribute, string|array $rules, callable $callback)

Add conditions to a given field based on a Closure.

Parameters

string $attribute
string|array $rules
callable $callback

Return Value

void

at line line 305
void each(string $attribute, string|array $rules)

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

Parameters

string $attribute
string|array $rules

Return Value

void

Exceptions

InvalidArgumentException

at line line 354
array extractValuesForWildcards(array $data, string $attribute)

Get all of the exact attribute values for a given wildcard attribute.

Parameters

array $data
string $attribute

Return Value

array

at line line 384
$this mergeRules(string $attribute, string|array $rules = array())

Merge additional rules into a given attribute(s).

Parameters

string $attribute
string|array $rules

Return Value

$this

at line line 420
bool passes()

Determine if the data passes the validation rules.

Return Value

bool

at line line 454
bool fails()

Determine if the data fails the validation rules.

Return Value

bool

at line line 466
void validate()

Run the validator's rules against its data.

Return Value

void

Exceptions

ValidationException

at line line 527
array valid()

Returns the data which was valid.

Return Value

array

at line line 543
array invalid()

Returns the data which was invalid.

Return Value

array

at line line 1539
string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

Parameters

string $attribute

Return Value

string

at line line 1736
bool isAValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

Parameters

mixed $value

Return Value

bool

at line line 2288
string getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

Parameters

string $attribute
mixed $value

Return Value

string

at line line 2632
array attributes()

Get all attributes.

Return Value

array

at line line 2643
bool hasAttribute(string $attribute)

Checks if an attribute exists.

Parameters

string $attribute

Return Value

bool

at line line 2655
bool hasRule(string $attribute, string|array $rules)

Determine if the given attribute has a rule in the given set.

Parameters

string $attribute
string|array $rules

Return Value

bool

at line line 2888
array getExtensions()

Get the array of custom validator extensions.

Return Value

array

at line line 2899
void addExtensions(array $extensions)

Register an array of custom validator extensions.

Parameters

array $extensions

Return Value

void

at line line 2916
void addImplicitExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

at line line 2932
void addExtension(string $rule, Closure|string $extension)

Register a custom validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 2944
void addImplicitExtension(string $rule, Closure|string $extension)

Register a custom implicit validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 2956
array getReplacers()

Get the array of custom validator message replacers.

Return Value

array

at line line 2967
void addReplacers(array $replacers)

Register an array of custom validator message replacers.

Parameters

array $replacers

Return Value

void

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

Register a custom validator message replacer.

Parameters

string $rule
Closure|string $replacer

Return Value

void

at line line 2995
array getData()

Get the data under validation.

Return Value

array

at line line 3006
$this setData(array $data)

Set the data under validation.

Parameters

array $data

Return Value

$this

at line line 3020
array getRules()

Get the validation rules.

Return Value

array

at line line 3031
$this setRules(array $rules)

Set the validation rules.

Parameters

array $rules

Return Value

$this

at line line 3050
$this setAttributeNames(array $attributes)

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

at line line 3063
$this setValueNames(array $values)

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

at line line 3077
PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

at line line 3092
void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

at line line 3102
TranslatorInterface getTranslator()

Get the Translator implementation.

Return Value

TranslatorInterface

at line line 3113
void setTranslator(TranslatorInterface $translator)

Set the Translator implementation.

Parameters

TranslatorInterface $translator

Return Value

void

at line line 3123
array getCustomMessages()

Get the custom messages for the validator.

Return Value

array

at line line 3134
void setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

at line line 3144
array getCustomAttributes()

Get the custom attributes used by the validator.

Return Value

array

at line line 3155
$this addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

at line line 3167
array getCustomValues()

Get the custom values for the validator.

Return Value

array

at line line 3178
$this addCustomValues(array $customValues)

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

at line line 3190
array getFallbackMessages()

Get the fallback messages for the validator.

Return Value

array

at line line 3201
void setFallbackMessages(array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

at line line 3211
array failed()

Get the failed validation rules.

Return Value

array

at line line 3221
MessageBag messages()

Get the message container for the validator.

Return Value

MessageBag

at line line 3235
MessageBag errors()

An alternative more semantic shortcut to the message container.

Return Value

MessageBag

at line line 3245
MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

at line line 3256
void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

at line line 3388
mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException