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
string
The property name
__set(string $name,string $value): void
string
The property name
string
The property value
getFirstMessage(string|array $tags = ''): string
string|array
If 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 ''.
string
The first error or warning message or empty string if no message exists
getLastMessage(string|array $tags = ''): string
string|array
If 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 ''.
string
The 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|array
If 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 ''.
integer
ValidationManager.OK, ValidationManager.WARNING or ValidationManager.ERROR
isArray(mixed $value,string $errorMessage = 'value is not an array',mixed $tags = '',boolean $isWarning = false): boolean
mixed
The array to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The boolean to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
First of the two objects to compare. Almost any type can be provided: ints, strings, arrays...
mixed
Second of the two objects to compare. Almost any type can be provided: ints, strings, arrays...
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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 |
---|
string
A text that must not be empty.
array
Optional 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.
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The number to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The number to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The object to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The object to validate.
array
An array of allowed properties that the object must have.
boolean
If 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.
string
The error message that will be generated if validation fails.
string
If set to true, extra information will be appended to the error message with details on which properties failed
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The element to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
A boolean expression to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False 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
mixed
The element to validate
string
The error message that will be generated if validation fails
mixed
We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state
boolean
Tells if the validation fail will be processed as a validation error or a validation warning
boolean
False in case the validation fails or true if validation succeeds.
notOk(string|array $tags = ''): boolean
string|array
If 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 ''.
boolean
True if status is warning or error, False if status is ok
ok(string|array $tags = ''): boolean
string|array
If 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 ''.
boolean
True 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