Class that allows us to manage application validation in an encapsulated way.
We can create as many instances as we want, and each instance will store the validation history and global validation state, so we can use this class to validate complex forms or multiple elements globally. We can also use tags to sandbox different validation elements or groups togheter.
| package | Default |
|---|
__get(string $name): void
stringThe property name
__set(string $name,string $value): void
stringThe property name
stringThe property value
getFirstMessage(string|array $tags = ''): string
string|arrayIf we want to filter only the warning / error messages by tag or list of tags, we can set it here. If we want to get the first of all messages, no matter which tag was applied, we will leave this value empty ''.
stringThe first error or warning message or empty string if no message exists
getLastMessage(string|array $tags = ''): string
string|arrayIf we want to filter only the warning / error messages by tag or list of tags, we can set it here. If we want to get the latest of all messages, no matter which tag was applied, we will leave this value empty ''.
stringThe last error or warning message or empty string if no message exists
getStatus(string|array $tags = ''): integer
Possible return values are ValidationManager.OK, ValidationManager.WARNING or ValidationManager.ERROR
string|arrayIf we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.
integerValidationManager.OK, ValidationManager.WARNING or ValidationManager.ERROR
isArray(mixed $value,string $errorMessage = 'value is not an array',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe array to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isBoolean(mixed $value,string $errorMessage = 'value is not a boolean',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe boolean to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isDate()
isEqualTo(mixed $value,mixed $value2,string $errorMessage = 'values are not equal',mixed $tags = '',boolean $isWarning = false): boolean
mixedFirst of the two objects to compare. Almost any type can be provided: ints, strings, arrays...
mixedSecond of the two objects to compare. Almost any type can be provided: ints, strings, arrays...
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isFilledIn(string $value,array $emptyChars = array(),string $errorMessage = 'value is required',mixed $tags = '',boolean $isWarning = false): boolean
| see | \org\turbocommons\src\main\php\managers\Stringutils::isEmpty |
|---|
stringA text that must not be empty.
arrayOptional array containing a list of string values that will be considered as empty for the given string. This can be useful in some cases when we want to consider a string like 'NULL' as an empty string.
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isHtmlFormValid()
isMail()
isMaximumLength()
isMinimumLength()
isMinimumWords()
isNIF()
isNumeric(mixed $value,string $errorMessage = 'value is not a number',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe number to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isNumericBetween(mixed $value, $min, $max,string $errorMessage = 'value is not between min and max',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe number to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isObject(mixed $value,string $errorMessage = 'value is not an object',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe object to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isObjectWithValidProperties(mixed $value,array $allowedProperties,boolean $strict = true,string $errorMessage = 'Invalid object',string $detailedErrorMessage = true,mixed $tags = '',boolean $isWarning = false): boolean
mixedThe object to validate.
arrayAn array of allowed properties that the object must have.
booleanIf true, the object must have exactly the properties specified in the allowedProperties array. If false, it is not mandatory that object has all the properties, it may have less. But in both cases all object properties must exist on the array of allowed.
stringThe error message that will be generated if validation fails.
stringIf set to true, extra information will be appended to the error message with details on which properties failed
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isPhone()
isPostalCode()
isString(mixed $value,string $errorMessage = 'value is not a string',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe element to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isTrue(mixed $value,string $errorMessage = 'value is not true',mixed $tags = '',boolean $isWarning = false): boolean
mixedA boolean expression to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
isUrl(mixed $value,string $errorMessage = 'value is not an URL',mixed $tags = '',boolean $isWarning = false): boolean
mixedThe element to validate
stringThe error message that will be generated if validation fails
mixedWe can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
booleanTells if the validation fail will be processed as a validation error or a validation warning
booleanFalse in case the validation fails or true if validation succeeds.
notOk(string|array $tags = ''): boolean
string|arrayIf we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.
booleanTrue if status is warning or error, False if status is ok
ok(string|array $tags = ''): boolean
string|arrayIf we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.
booleanTrue if status is ok, false if status is warning or error
reset(): void
This is normally called at the beginning of every global validation we perform. It will reset all the validation errors on this class and for all tags, so we can re validate whatever we need to.
OK
WARNING
ERROR