Validator
- Full name:
\Qubus\Validation\Validator
- This class implements:
\Qubus\Validation\Validatable
Properties
translator
The StringTranslator implementation.
presenceVerifier
The Presence Verifier implementation.
failedRules
The failed validation rules.
messages
The messages.
data
The data under validation.
files
The files under validation.
rules
The rules to be applied to the data.
after
All the registered "after" callbacks.
customMessages
The array of custom error messages.
fallbackMessages
The array of fallback error messages.
customAttributes
The array of custom attribute names.
customValues
The array of custom displayable values.
extensions
All the custom validator extensions.
replacers
All the custom replacer extensions.
sizeRules
The size related validation rules.
numericRules
The numeric related validation rules.
implicitRules
The validation rules that imply the field is required.
Methods
__construct
Create a new Validator instance.
public __construct(\Qubus\Validation\Translators\StringTranslator $translator, array $data, array $rules, array $messages = [], array $customAttributes = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$translator | \Qubus\Validation\Translators\StringTranslator | |
$data | array | |
$rules | array | |
$messages | array | |
$customAttributes | array |
parseData
Parse the data and hydrate the files array.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array |
explodeRules
Explode the rules into an array of rules.
Parameters:
Parameter | Type | Description |
---|---|---|
$rules | array|string |
after
After an after validation callback.
Parameters:
Parameter | Type | Description |
---|---|---|
$callback | callable|string |
sometimes
Add conditions to a given field based on a Closure.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rules | array|string | |
$callback | callable |
each
Define a set of rules that apply to each element in an array attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rules | array|string |
Throws:
mergeRules
Merge additional rules into a given attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rules | array|string |
passes
Determine if the data passes the validation rules.
fails
Determine if the data fails the validation rules.
validate
Validate a given attribute against a rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rule | string |
getValue
Get the value of a given attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string |
isValidatable
Determine if the attribute is validatable.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$attribute | string | |
$value | mixed |
presentOrRuleIsImplicit
Determine if the field is present, or the rule implies required.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$attribute | string | |
$value | mixed |
passesOptionalCheck
Determine if the attribute passes any optional check.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string |
isImplicit
Determine if a given rule implies the attribute is required.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string |
addFailure
Add a failed rule and error message to the collection.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rule | string | |
$parameters | array |
addError
Add an error message to the validator's collection of messages.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rule | string | |
$parameters | array |
validateSometimes
"Validate" optional attributes.
Always returns true, just lets us put sometimes in rules.
validateRequired
Validate that a required attribute exists.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateFilled
Validate the given attribute is filled if it is present.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
anyFailingRequired
Determine if any of the given attributes fail the required test.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array |
allFailingRequired
Determine if all the given attributes fail the required test.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array |
validateRequiredWith
Validate that an attribute exists when any other attribute exists.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | mixed |
validateRequiredWithAll
Validate that an attribute exists when all other attributes exists.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | mixed |
validateRequiredWithout
Validate that an attribute exists when another attribute does not.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | mixed |
validateRequiredWithoutAll
Validate that an attribute exists when all other attributes do not.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | mixed |
validateRequiredIf
Validate that an attribute exists when another attribute has a given value.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | mixed |
Throws:
getPresentCount
Get the number of attributes in a list that are present.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array |
validateConfirmed
Validate that an attribute has a matching confirmation.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
Throws:
validateSame
Validate that two attributes match.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateDifferent
Validate that an attribute is different from another attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateAccepted
Validate that an attribute was "accepted".
This validation rule implies the attribute is "required".
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateBoolean
Validate that an attribute is a boolean.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateArray
Validate that an attribute is an array.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateNumeric
Validate that an attribute is numeric.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateInteger
Validate that an attribute is an integer.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateDigits
Validate that an attribute has a given number of digits.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateDigitsBetween
Validate that an attribute is between a given number of digits.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateSize
Validate the size of an attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateBetween
Validate the size of an attribute is between a set of values.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateMin
Validate the size of an attribute is greater than a minimum value.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateMax
Validate the size of an attribute is less than a maximum value.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
getSize
Get the size of an attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
getStringSize
Get the size of a string.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | string |
validateIn
Validate an attribute is contained within a list of values.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
validateNotIn
Validate an attribute is not contained within a list of values.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
validateUnique
Validate the uniqueness of an attribute value on a given database table.
If a database column is not specified, the attribute will be used.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
getUniqueIds
Get the excluded ID column and value for the unique rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$parameters | array |
getUniqueExtra
Get the extra conditions for a unique rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$parameters | array |
validateExists
Validate the existence of an attribute value in a database table.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
getExistCount
Get the number of records that exist in storage.
Parameters:
Parameter | Type | Description |
---|---|---|
$table | string | |
$column | string | |
$value | mixed | |
$parameters | array |
getExtraExistConditions
Get the extra exist conditions.
Parameters:
Parameter | Type | Description |
---|---|---|
$parameters | array |
getExtraConditions
Get the extra conditions for a unique / exists rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$segments | array |
validateIp
Validate that an attribute is a valid IP.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateIpv4
Validate that an attribute is a valid IPv4.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateIpv6
Validate that an attribute is a valid IPv6.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateEmail
Validate that an attribute is a valid e-mail address.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateUrl
Validate that an attribute is a valid URL.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateActiveUrl
Validate that an attribute is an active URL.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateImage
Validate the MIME type of file is an image MIME type.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateMimes
Validate the MIME type of file upload attribute is in a set of MIME types.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | array | |
$parameters | array |
validateAlpha
Validate that an attribute contains only alphabetic characters.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateAlphaNum
Validate that an attribute contains only alphanumeric characters.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateAlphaDash
Validate that an attribute contains only alphanumeric characters, dashes, and underscores.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateRegex
Validate that an attribute passes a regular expression check.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateDate
Validate that an attribute is a valid date.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
validateDateFormat
Validate that an attribute matches a date format.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateBefore
Validate the date is before a given date.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateBeforeWithFormat
Validate the date is before a given date with a given format.
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string | |
$value | mixed | |
$parameters | array |
validateAfter
Validate the date is after a given date.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed | |
$parameters | array |
Throws:
validateAfterWithFormat
Validate the date is after a given date with a given format.
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string | |
$value | mixed | |
$parameters | array |
checkDateTimeOrder
Given two date/time strings, check that one is after the other.
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string | |
$before | string | |
$after | string |
getDateTimeWithOptionalFormat
Get a DateTime instance from a string.
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string | |
$value | string |
validateTimezone
Validate that an attribute is a valid timezone.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
Throws:
getDateFormat
Get the date format for an attribute if it has one.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string |
getMessage
Get the validation message for an attribute and rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rule | string |
getInlineMessage
Get the inline message for a rule if it exists.
protected getInlineMessage(string $attribute, string $lowerRule, array|null $source = null): mixed|void
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$lowerRule | string | |
$source | array|null |
getSizeMessage
Get the proper error message for an attribute and size rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rule | string |
getAttributeType
Get the data type of the given attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string |
doReplacements
Replace all error message place-holders with actual values.
protected doReplacements(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
getAttributeList
Transform an array of attributes to their displayable form.
Parameters:
Parameter | Type | Description |
---|---|---|
$values | array |
getAttribute
Get the displayable name of the attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string |
getDisplayableValue
Get the displayable name of the value.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$value | mixed |
replaceBetween
Replace all place-holders for the between rule.
protected replaceBetween(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceDigits
Replace all place-holders for the digits rule.
protected replaceDigits(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceDigitsBetween
Replace all place-holders for the digits (between) rule.
protected replaceDigitsBetween(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceSize
Replace all place-holders for the size rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceMin
Replace all place-holders for the min rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceMax
Replace all place-holders for the max rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceIn
Replace all place-holders for the in rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceNotIn
Replace all place-holders for the not_in rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceMimes
Replace all place-holders for the mimes rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceRequiredWith
Replace all place-holders for the required_with rule.
protected replaceRequiredWith(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceRequiredWithAll
Replace all place-holders for the required_with_all rule.
protected replaceRequiredWithAll(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceRequiredWithout
Replace all place-holders for the required_without rule.
protected replaceRequiredWithout(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceRequiredWithoutAll
Replace all place-holders for the required_without_all rule.
protected replaceRequiredWithoutAll(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceRequiredIf
Replace all place-holders for the required_if rule.
protected replaceRequiredIf(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceSame
Replace all place-holders for the same rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceDifferent
Replace all place-holders for the different rule.
protected replaceDifferent(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceDateFormat
Replace all place-holders for the date_format rule.
protected replaceDateFormat(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceBefore
Replace all place-holders for the before rule.
protected replaceBefore(string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
replaceAfter
Replace all place-holders for the after rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
hasRule
Determine if the given attribute has a rule in the given set.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rules | array|string |
getRule
Get a rule and its parameters for a given attribute.
Parameters:
Parameter | Type | Description |
---|---|---|
$attribute | string | |
$rules | array|string |
parseRule
Extract the rule name and parameters from a rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$rules | array|string |
parseArrayRule
Parse an array based rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$rules | array |
parseStringRule
Parse a string based rule.
Parameters:
Parameter | Type | Description |
---|---|---|
$rules | string |
parseParameters
Parse a parameter list.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$parameter | string |
addExtensions
Register an array of custom validator extensions.
Parameters:
Parameter | Type | Description |
---|---|---|
$extensions | array |
addImplicitExtensions
Register an array of custom implicit validator extensions.
Parameters:
Parameter | Type | Description |
---|---|---|
$extensions | array |
addExtension
Register a custom validator extension.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$extension | string|\Closure |
addImplicitExtension
Register a custom implicit validator extension.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$extension | string|\Closure |
addReplacers
Register an array of custom validator message replacers.
Parameters:
Parameter | Type | Description |
---|---|---|
$replacers | array |
addReplacer
Register a custom validator message replacer.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$replacer | string|\Closure |
getRules
Get the validation rules.
setRules
Set the validation rules.
Parameters:
Parameter | Type | Description |
---|---|---|
$rules | array |
setAttributeNames
Set the custom attributes on the validator.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array |
setValueNames
Set the custom values on the validator.
Parameters:
Parameter | Type | Description |
---|---|---|
$values | array |
getFiles
Get the files under validation.
setFiles
Set the files under validation.
Parameters:
Parameter | Type | Description |
---|---|---|
$files | array |
getPresenceVerifier
Get the Presence Verifier implementation.
setPresenceVerifier
Set the Presence Verifier implementation.
Parameters:
Parameter | Type | Description |
---|---|---|
$presenceVerifier | \Qubus\Validation\Interfaces\PresenceVerifier |
addCustomAttributes
Add custom attributes to the validator.
Parameters:
Parameter | Type | Description |
---|---|---|
$customAttributes | array |
addCustomValues
Add the custom values for the validator.
Parameters:
Parameter | Type | Description |
---|---|---|
$customValues | 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.
callExtension
Call a custom validator extension.
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | |
$parameters | array |
callClassBasedExtension
Call a class based validator extension.
Parameters:
Parameter | Type | Description |
---|---|---|
$callback | string | |
$parameters | array |
callReplacer
Call a custom validator message replacer.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
callClassBasedReplacer
Call a class based validator message replacer.
protected callClassBasedReplacer(string $callback, string $message, string $attribute, string $rule, array $parameters): string
Parameters:
Parameter | Type | Description |
---|---|---|
$callback | string | |
$message | string | |
$attribute | string | |
$rule | string | |
$parameters | array |
requireParameterCount
Require a certain number of parameters to be present.
Parameters:
Parameter | Type | Description |
---|---|---|
$count | int | |
$parameters | array | |
$rule | string |
Throws:
__call
Handle dynamic calls to class methods.
Parameters:
Parameter | Type | Description |
---|---|---|
$method | string | |
$parameters | array |
Throws:
Automatically generated on 2025-10-13