Jet\Validator
Base abstract class from which all validators must inherit.
| Method | Meaning |
|---|---|
| public static getType( ) : string |
Returns the string identifier of the validator type. |
| public getErrorMessages( ) : array |
Returns a list of configured error messages as an associative array where the key represents the error code and the value represents the error message. |
| public setErrorMessages( array $error_messages ) : void |
Sets error messages as an associative array where the key represents the error code and the value represents the error message. |
| public getErrorMessageGenerator( ) : Validator_ErrorMessageGenerator |
Returns the currently configured error message generator. If no custom generator is set, it uses a simple connection to the translator subsystem. |
| public setErrorMessageGenerator( ?Validator_ErrorMessageGenerator $error_message_generator ) : void |
Sets the error message generator. |
| public generateErrorMessage( string $code, array $data ) : string |
Generates an error message. In practice, this is a bridge that calls the error message generator. |
| public setError( string $code, array $data = [] ) : void |
Sets the validator to an error state. |
| public getAllErrors( ) : Validator_ValidationError[] |
Returns a list of all validation errors if any occurred. |
| public getLastErrorCode( ) : string |
Returns the error code of the last validation error if any occurred. |
| public getLastErrorMessage( ) : string |
Returns the last human-readable error message of the last validation error if any occurred. |
| public getLastErrorData( ) : array |
Returns the contextual data of the last validation error if any occurred. |
| public setIsRequired( bool $is_required ) : void |
Sets whether the value is required. If it is not and the input is empty, the validator considers the input valid. |
| public getIsRequired( ) : bool |
Returns true if the validator is set to require a value. |
| public setIsValid( ) : void |
Resets the validator – everything is cleared and the validator is set to the "valid" state. |
| public isValid( ) : bool |
Indicates whether the validator is in the "valid" state. |
| protected validate_required( mixed $value ) : bool |
Base test – is there a value on input and does it comply with the current configuration? If the value is not required and no value is provided on input, the validator is set to the "valid" state and no further validation takes place. If the value is required and not provided on input, an error occurs automatically, and naturally no further validation is performed in this scenario either. Only after this check does the validation of the actual value follow. |
| abstract public validate_value( mixed $value ) : bool |
Abstract method specific to each validator type, performing the actual value validation. |
| public getErrorCodeScope( ) : array |
Returns a list of error codes known to the given validator with its current configuration. |
| public validate( mixed $value ) : bool |
Validates the given value. Returns true if the value is valid. Otherwise, returns false and validation errors are generated (see, for example, the getAllErrors method). |
| public static getValidatorOptionsDefinition( ) : Entity_Validator_Definition_ValidatorOption[] |
Returns the definition of options/parameters that the validator can have. |