Files
huangjingfen/pro_v3.5.1/crmeb/form/validate/BaseRules.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

67 lines
1.5 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace crmeb\form\validate;
use crmeb\form\CommonRule;
/**
* Class BaseRules
* @package crmeb\form\validate
* @method CommonRule required() 是否必填
* @method CommonRule message(string $message) 设置错误提示
* @method CommonRule enum(array $enum) 枚举
* @method CommonRule pattern(string $pattern) 正则表达式
* @method CommonRule field($field, array $rule = []) 验证规则
*/
abstract class BaseRules
{
/**
* 是否初始化
* @var bool
*/
protected static $init = false;
/**
* @var CommonRule
*/
protected static $rule;
/**
* @return mixed
*/
public static function getType(): string
{
return '';
}
/**
* 初始化
*/
public static function init()
{
if (!self::$init) {
self::$rule = new CommonRule();
self::$rule->type(static::getType());
self::$init = true;
}
}
/**
* @param $name
* @param $arguments
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
self::init();
if (method_exists(self::$rule, $name)) {
return self::$rule->{$name}(...$arguments);
}
throw new FormValidate(__CLASS__ . ' Method does not exist' . $name . '()');
}
}