本文整理汇总了PHP中Check::method方法的典型用法代码示例。如果您正苦于以下问题:PHP Check::method方法的具体用法?PHP Check::method怎么用?PHP Check::method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Check
的用法示例。
在下文中一共展示了Check::method方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: errors
public static function errors()
{
return static::$errors;
}
}
Event::on('core.check.init', function () {
Check::method(['required' => function ($value) {
return is_numeric($value) && $value == 0 || empty($value) ? 'This value cant\' be empty.' : true;
}, 'alphanumeric' => function ($value) {
return preg_match('/^\\w+$/', $value) ? true : 'Value must be alphanumeric.';
}, 'numeric' => function ($value) {
return preg_match('/^\\d+$/', $value) ? true : 'Value must be numeric.';
}, 'email' => function ($value) {
return filter_var($value, FILTER_VALIDATE_EMAIL) ? true : 'This is not a valid email.';
}, 'url' => function ($value) {
return filter_var($value, FILTER_VALIDATE_URL) ? true : 'This is not a valid URL.';
}, 'max' => function ($value, $max) {
return $value <= $max ? true : 'Value must be less than ' . $max . '.';
}, 'min' => function ($value, $min) {
return $value >= $min ? true : 'Value must be greater than ' . $min . '.';
}, 'range' => function ($value, $min, $max) {
return $value >= $min && $value <= $max ? true : "This value must be in [{$min},{$max}] range.";
}, 'words' => function ($value, $max) {
return str_word_count($value) <= $max ? true : 'Too many words, max count is ' . $max . '.';
}, 'length' => function ($value, $max) {
return strlen($value) <= $max ? true : 'Too many characters, max count is ' . $max . '.';
}, 'same_as' => function ($value, $fieldname) {
$x = isset(Check::$data[$fieldname]) ? Check::$data[$fieldname] : '';
return $value == $x ? true : 'Field must be equal to ' . $fieldname . '.';
}]);
});
示例2: function
Check::method(['required' => ['validate' => function ($value) {
return is_numeric($value) && $value == 0 || !empty($value);
}, 'message' => "This value cannot be empty."], 'alphanumeric' => ['validate' => function ($value) {
return (bool) preg_match('/^[0-9a-zA-Z]+$/', $value);
}, 'message' => "Value must be alphanumeric."], 'numeric' => ['validate' => function ($value) {
return (bool) preg_match('/^\\d+$/', $value);
}, 'message' => "Value must be numeric."], 'email' => ['validate' => function ($value) {
return (bool) filter_var($value, FILTER_VALIDATE_EMAIL);
}, 'message' => "This is not a valid email."], 'url' => ['validate' => function ($value) {
return (bool) filter_var($value, FILTER_VALIDATE_URL);
}, 'message' => "This is not a valid URL."], 'max' => ['validate' => function ($value, $max) {
return $value <= $max ? true : false;
}, 'message' => "Value must be less than {{arg_1}}."], 'min' => ['validate' => function ($value, $min) {
return $value >= $min;
}, 'message' => "Value must be greater than {{arg_1}}."], 'range' => ['validate' => function ($value, $min, $max) {
return $value >= $min && $value <= $max;
}, 'message' => "This value must be in [{{arg_1}},{{arg_2}}] range."], 'words' => ['validate' => function ($value, $max) {
return str_word_count($value) <= $max;
}, 'message' => "Too many words, max count is {{arg_1}}."], 'length' => ['validate' => function ($value, $length) {
return strlen($value) == $length;
}, 'message' => "This value must be {{arg_1}} characters."], 'min_length' => ['validate' => function ($value, $min) {
return strlen($value) >= $min;
}, 'message' => "Too few characters, min count is {{arg_1}}."], 'max_length' => ['validate' => function ($value, $max) {
return strlen($value) <= $max;
}, 'message' => "Too many characters, max count is {{arg_1}}."], 'true' => ['validate' => function ($value) {
return (bool) $value;
}, 'message' => "This value must be true."], 'false' => ['validate' => function ($value) {
return !$value;
}, 'message' => "This value must be false."], 'same_as' => ['validate' => function ($value, $fieldname) {
$x = isset(Check::$data[$fieldname]) ? Check::$data[$fieldname] : '';
return $value == $x;
}, 'message' => "Field must be equal to {{arg_1}}."], 'in_array' => ['validate' => function ($value, $array_values) {
return in_array($value, $array_values);
}, 'message' => "This value is forbidden."]]);