本文整理汇总了PHP中Respect\Validation\Validator::buildRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::buildRule方法的具体用法?PHP Validator::buildRule怎么用?PHP Validator::buildRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::buildRule方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRule
public function addRule($validator, $arguments = array())
{
if (!$validator instanceof Validatable) {
$this->appendRule(Validator::buildRule($validator, $arguments));
} else {
$this->appendRule($validator);
}
return $this;
}
示例2: validateField
/**
* Validate a field's value with a given $rule
*
* @param $value mixed Value to validate
* @param $rule mixed Rule(s) to use for validation
* @return bool
*/
public static function validateField($value, $rule)
{
// only validate non-empty fields
if ($value == "") {
return true;
}
// validate
$validator = new Validator();
// create rules
if (!is_array($rule)) {
$validator->addRule(Validator::buildRule($rule));
} else {
foreach ($rule as $rule_key => $params) {
$params = Helper::ensureArray($params);
$validator->addRule(Validator::buildRule($rule_key, $params));
}
}
return $validator->validate($value);
}
示例3: handleValidationRule
/**
* Smart method to process fields, regardless of data type
*
* @param string $field Field to validate
* @param mixed $rule Rule (or rules) to chain and validate with
* @return bool
*/
private function handleValidationRule($field, $rule)
{
if ($field == '') {
return true;
}
# only validate non-empty fields.
$spawn = new v();
if (!is_array($rule)) {
$spawn->addRule(v::buildRule($rule));
} else {
foreach ($rule as $rule_key => $params) {
$params = !is_array($params) ? (array) $params : $params;
# make sure params are an array
$spawn->addRule(v::buildRule($rule_key, $params));
}
}
return $spawn->validate($field);
}