lithium\util\Validator::rule()

public static method

Checks a single value against a single validation rule in one or more formats.

Parameters

  • string $rule
  • mixed $value
  • string $format
  • array $options

Returns

boolean

Returns 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 = array()) {
		if (!isset(static::$_rules[$rule])) {
			throw new InvalidArgumentException("Rule `{$rule}` is not a validation rule.");
		}
		$defaults = isset(static::$_options[$rule]) ? static::$_options[$rule] : array();
		$options = (array) $options + $defaults + static::$_options['defaults'];

		$ruleCheck = static::$_rules[$rule];
		$ruleCheck = is_array($ruleCheck) ? $ruleCheck : array($ruleCheck);

		if (!$options['contains'] && !empty($ruleCheck)) {
			foreach ($ruleCheck as $key => $item) {
				$ruleCheck[$key] = is_string($item) ? "/^{$item}$/" : $item;
			}
		}

		$params = compact('value', 'format', 'options');
		return static::_filter($rule, $params, static::_checkFormats($ruleCheck));
	}