$mapper = new ModelMapper();
$myObject = $mapper->unmap($myModel);
$model->validate('createAction');
$model->validate();
$model = new Model();
$validator = new ModelValidator();
$validator->validate($model, 'myAction');
/**
* @rule email
*/
public $email;
/**
* @rule limit(0,99)
*/
public $value;
use Common\ModelReflection\ModelProperty;
use Validator\IRule;
use Validator\ModelValidatorException;
class LimitRule implements IRule {
function getNames() {
return ['limit'];
}
function validate(ModelProperty $property, array $params = []) {
if($property->getPropertyValue() < $params[0] || $property->getPropertyValue() > $params[1]) {
throw new ModelValidatorException('Value is not between '.$params[0].' and '.$params[1]);
}
}
}
$model = new Model();
$myCustomRule = new MyCustomRule();
$validator = new ModelValidator();
$validator->useRule($myCustomRule);
$validator->loadRules('/path/to/rules/');
$validator->validate($model, 'myAction');
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.