lithium\util\Validator::rule()
Checks a single value against a single validation rule in one or more formats.
Parameters
-
string
$rule
-
mixed
$value
-
string
$format
-
array
$options
Returns
booleanReturns true
or false
indicating whether the validation rule check
succeeded or failed.
Filter
This method can be filtered.
Source
public static function rule($rule, $value, $format = 'any', array $options = []) {
if (!isset(static::$_rules[$rule])) {
throw new InvalidArgumentException("Rule `{$rule}` is not a validation rule.");
}
$defaults = isset(static::$_options[$rule]) ? static::$_options[$rule] : [];
$options = (array) $options + $defaults + static::$_options['defaults'];
$ruleCheck = static::$_rules[$rule];
$ruleCheck = is_array($ruleCheck) ? $ruleCheck : [$ruleCheck];
if (!$options['contains'] && !empty($ruleCheck)) {
foreach ($ruleCheck as $key => $item) {
$ruleCheck[$key] = is_string($item) ? "/^{$item}$/" : $item;
}
}
$params = compact('value', 'format', 'options');
return Filters::run(get_called_class(), $rule, $params, static::_checkFormats($ruleCheck));
}