Menu

Maslosoft Mangan Logo Maslosoft Mangan Documentation
MongoDB Object Persister

Edit

Validator Annotation

Annotation @Validator provides option to place arbitrary validator on model attribute. It takes as a first argument validator class name and other arguments will be passed to validator properties.

Minimal example of using @Validator with (custom) validator:

@Validator(MyValidator)

To pass extra arguments for validator, use named parameters.

Example uf using built-in validator with parameter:

@Validator(StringValidator, min = 10)

There are also extra annotations for common validators. This is to provide easier and possibly more obvious validation instructions.

Example of using built-in predefined validator annotations:

/**
* @RequiredValidator
* @UniqueValidator
*/
public $host = '';

Above code will ensure that attribute is not empty and that it is unique in collection.

Read more about data validation