Extends
lithium\core\StaticObject
Perform validation checks against a value using an array of all possible formats for a rule,
and an array specifying which formats within the rule to use.
Parameters
- array $rules All available rules.
Returns
closure Function returning boolean `true` if validation succeeded, `false` otherwise.Source
protected static function _checkFormats($rules) {
return function($self, $params, $chain) use ($rules) {
$value = $params['value'];
$format = $params['format'];
$options = $params['options'];
$defaults = array('all' => true);
$options += $defaults;
$formats = (array) $format;
$options['all'] = ($format == 'any');
foreach ($rules as $index => $check) {
if (!$options['all'] && !(in_array($index, $formats) || isset($formats[$index]))) {
continue;
}
$regexPassed = (is_string($check) && preg_match($check, $value));
$closurePassed = (is_object($check) && $check($value, $format, $options));
if (!$options['all'] && ($regexPassed || $closurePassed)) {
return true;
}
if ($options['all'] && (!$regexPassed && !$closurePassed)) {
return false;
}
}
return $options['all'];
};
}