本文整理匯總了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);
}