NewsFeaturesDownloadsDevelopmentSupportAbout Us

Validator_Rules


Classes

class  ArrayRule
class  EmailDnsRule
class  EmailFormatRule
class  EqualRule
class  IntRule
class  IpCidrFormatRule
class  IpFormatRule
class  IpRangeRule
class  NonEmptyRule
class  NumericRule
class  RangeRule
class  Rule
class  UIntRule
class  UrlFormatRule

Detailed Description

The main classes that implement the Strategy pattern as described here http://www.phppatterns.com/index.php/article/articleview/13/1/1/ are the classes that extend the Validator interface.

But at a deeper level, a Validator class is nothing else than a collection of rules, or classes that extend the Rule interface. Implementing Validator classes as a collection of Rule classes allows for better code reusability, since sometimes most of the Validator classes check for similar things and therefore we can reuse most of the Rule classes.

In order to implement your own rule, simply create your own class extending the Rule class and make sure to implement the Rule.Validate() method with your own validation logic. This method should return 'true' if the data complies with the logic of the rule or 'false' if it does not. Additionally, since Rule extends the Validation interface it is also possible to set certain error flags or messages via the private method Validation._setError(). These error codes can be checked by Validator classes or by users of this class via the Validation.getError() method.

See the documentation of the Validator base class on how to use Rule classes in your own validators.

See also:
Validator