Classes | |
| class | ArrayValidator |
| class | BlogNameValidator |
| class | ChainedValidator |
| class | DateTimeValidator |
| class | DomainValidator |
| class | EmailValidator |
| class | EmptyValidator |
| class | FloatValidator |
| class | HttpUrlValidator |
| class | IntegerValidator |
| class | IpMatchValidator |
| class | PasswordValidator |
| class | StringValidator |
| class | TemplateNameValidator |
| class | TemplateSetValidator |
| class | UploadValidator |
| class | UsernameValidator |
| class | Validation |
| class | Validator |
Validator classes allow to reuse validation logic wherever needed, and in a uniform way since class users can safely assume that all validators implement the Validator.validate() method.
Validator classes in pLog can be built as a set of Rules, as a set of chained Validator classes or they can also bring their own non-reusable logic (non-reusable in the sense that validation logic does not necessarily need to be part of a Rule class)
This the preferred way to validate data using a Validator class in pLog:
$val = new UsernameValidator();
if( !$val->validate( $newUsername ))
print( "the username $newUsername is not correct!" );
else
print( "the username is correct" );
It is also possible to implemlent our own custom validators by extending the Validator base class and adding a few rules. Keep in mind that if we overwrite the Validator.validate() method, we will lose some logic regarding rules. If our Validator class does not use rules, it is safe to overwrite such method and return 'true' if successful or false otherwise.
In order to implement our own validator, the preferred way of doing it is by adding the necessary Validator and Rule objects in the constructor:
class NewValidator extend Validator { function NewValidator() { $this->addRule( new NonEmptyRule()); $this->addRule( new NumericRule()); } }