创建验证规则
根据配置自动添加$this->createdAtAttribute和$this->updatedAtAttribute属性的验证规则，同时滤掉该行为的其他规则

@param array $modelRules 模型验证规则

@return array 验证规则
189554
public function createRules(array $modelRules)
    {
        // 删除规则里有关时间日期字段的所有规则，由系统判断是否需要添加相应的规则。如需对时间日期字段添加其他规则，
        // 可合并需要的规则到该方法调用后返回的数据结果里
        foreach ($modelRules as $key => &$rule) {
            if (is_array($rule[0])) {
                foreach ($rule[0] as $k => $v) {
                    if (in_array($v, [$this->createdAtAttribute, $this->updatedAtAttribute])) {
                        unset($rule[0][$k]);
                    }
                }
                if (count($rule[0]) === 0) {
                    unset($modelRules[$key]);
                }
            } else {
                if (in_array($rule[0], [$this->createdAtAttribute, $this->updatedAtAttribute])) {
                    unset($modelRules[$key]);
                }
            }
        }
        // 添加相应规则
        $rules = [];
        $attributes = [
            [
                $this->createdAtAttribute,
                $this->modifyCreatedAt,
            ],
            [
                $this->updatedAtAttribute,
                $this->modifyUpdatedAt,
            ],
        ];
        foreach ($attributes as $row) {
            if (is_string($row[0])) {
                // 允许自定义时间日期
                if ($row[1]) {
                    $this->addRules($rules, $row[0]);
                } // 不允许自定义时间日期则暂不需要添加其他规则，系统会根据配置自动为时间日期字段赋值$this->value
                else {
                    continue;
                }
            }
        }
        
        return ArrayHelper::merge($modelRules, $rules);
    }
598269
public function applyRules(array $rules = [], array $data = []): array
    {
        $data  = $data ?: $this->_data;
        $rules = $rules ?: $this->_rules;
        // save clean data
        $filtered = [];

        foreach ($rules as $rule) {
            if (!isset($rule[0], $rule[1])) {
                continue;
            }

            if (!$fields = $rule[0]) {
                continue;
            }

            $fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;

            foreach ($fields as $field) {
                if (!isset($data[$field])) {
                    $filtered[$field] = $rule['default'] ?? null;
                } else {
                    $filtered[$field] = $this->valueFiltering($data[$field], $rule[1]);
                }
            }
        }

        return $filtered;
    }
642321
function buildReorderRules()
    {
        $matrix     = $this->attribute( 'matrix' );
        $columns    = $matrix['columns']['sequential'];
        $rules      = array();
        $positions  = array_keys( $columns );

        foreach ( $columns as $pos => $column )
        {
            if ( $this->hasRuleForColumn( $rules, $pos ) )
            {
                continue;
            }

            if ( $column['index'] != $pos )
            {
                $rules[] = $this->buildReorderRuleForColumn( $columns, $pos );
            }
        }
        return $rules;
    }
547500
public function filterRules($rules)
    {
        foreach ($this->_behaviors as $name => $foo) {
            if (($behavior = $this->getBehavior($name)) instanceof \nineinchnick\usr\components\FormModelBehavior) {
                $rules = $behavior->filterRules($rules);
            }
        }

        return $rules;
    }
936138
public function getModelsFromResult($modelResult)
    {
        $modelsArray = [];

        if (isset($modelResult['models'])) {
            foreach ($modelResult['models'] as $model) {
                $model = new Model($model);
                $modelsArray[] = $model;
            }
        } else {
            throw new \Exception('Models Not Found');
        }

        return $modelsArray;
    }
893592
protected function processRules()
	{
		$this->cache = !YII_DEBUG;
		// Generate the clientRules
		$this->rules = $this->cache ? Yii::app()->cache->get('CiiMS::Routes') : array();
		if ($this->rules == false || empty($this->rules))
		{
			$this->rules = array();
			$this->rules = $this->generateClientRules();
			$this->rules = CMap::mergearray($this->addRssRules(), $this->rules);
			$this->rules = CMap::mergeArray($this->addModuleRules(), $this->rules);

			Yii::app()->cache->set('CiiMS::Routes', $this->rules);
		}

		// Append our cache rules BEFORE we run the defaults
		$this->rules['<controller:\w+>/<action:\w+>/<id:\d+>'] = '<controller>/<action>';
		$this->rules['<controller:\w+>/<action:\w+>'] = '<controller>/<action>';

		return parent::processRules();
	}
1351857
public static function loadMultiple($data, $modelClass, $models = [], $requiredData = [])
    {
        $result = ['models' => $models, 'errors' => []];
        if (!$data) {
            return $result;
        }
        if (!is_array($models)) {
            $data =  [@$models->id => $data];
            $models = [@$models->id => $models];
            $result = ['models' => $models, 'errors' => []];
        }
        $lastIndex = count($models);
        foreach ($data as $id => $attributes) {
            $modelSearch = array_filter($models, function($v) use($id){return $v['id'] == $id;});
            /** @var Model $model */
            $model = reset($modelSearch) ? : new $modelClass();
            foreach ($requiredData as $k => $v) {
                $model->$k = $v;
            }
            $model->load($attributes, '');
            $index = $modelSearch ? key($modelSearch) : $lastIndex++;
            $result['models'][$index] = $model;
            $model->isAttributeSafe('scenario');
            if (!$model->validate()) {
                $result['errors'][$index] = $model->errors;
            }
        }

        return $result;
    }
1058030
public function getValidationRules()
    {
        $rules = $this->getOption('rules', []);
        $name = $this->getNameKey();
        $messages = $this->getOption('error_messages', []);
        $formName = $this->formHelper->transformToDotSyntax($this->parent->getName());

        if ($messages && $formName) {
            $newMessages = [];
            foreach ($messages as $messageKey => $message) {
                $messageKey = sprintf('%s.%s', $formName, $messageKey);
                $newMessages[$messageKey] = $message;
            }
            $messages = $newMessages;
        }

        if (!$rules) {
            return (new Rules([]))->setFieldName($this->getNameKey());
        }

        if (is_array($rules)) {
            $rules = array_map(function ($rule) use ($name) {
                if ($rule instanceof \Closure) {
                    return $rule($name);
                }

                return $rule;
            }, $rules);
        }

        return (new Rules(
            [$name => $rules],
            [$name => $this->getOption('label')],
            $messages
        ))->setFieldName($this->getNameKey());
    }
773201
protected function parseFailedRules($failedRules)
    {
        // Parsed failed rules container
        $parsedFailedRules = [];

        foreach ($failedRules as $field => $ruleAttributes) {
            foreach ($ruleAttributes as $rule => $attributes) {
                $parsedFailedRules[$field] = strtolower($field.'.'.$rule);
            }
        }

        return $parsedFailedRules;
    }
1147432
public function rules(): array
    {
        $user = $this->user($this->route('guard'));

        // Attach attribute rules
        $user->getEntityAttributes()->each(function ($attribute, $attributeName) use (&$rules) {
            switch ($attribute->type) {
                case 'datetime':
                    $type = 'date';
                    break;
                case 'text':
                case 'check':
                case 'select':
                case 'varchar':
                    $type = 'string';
                    break;
                default:
                    $type = $attribute->type;
                    break;
            }

            $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type;
            $rules[$attributeName.($attribute->is_collection ? '.*' : '')] = $rule;
        });

        return $rules ?? [];
    }
865641
public function createValidationRules() {
		$configAcLimit = $this->_modelConfigSettingsApp->getFlagConfigAcLimit();
		$configADsearch = $this->_modelConfigSettingsApp->getFlagConfigADsearch();
		$configSMTP = $this->_modelConfigSettingsApp->getFlagConfigSmtp();
		$configExtAuth = $this->_modelConfigSettingsApp->getFlagConfigExtAuth();
		$authGroups = $this->_modelConfigSettingsApp->getAuthGroups();
		$validator = $this->validator();
		if (!$configAcLimit) {
			unset($validator['AutocompleteLimit']);
		}
		if (!$configADsearch) {
			unset($validator['Company']);
			unset($validator['SearchBase']);
		}
		if (!$configExtAuth) {
			unset($validator['ExternalAuth']);
		}
		if (!$configSMTP) {
			unset($validator['EmailSmtphost']);
			unset($validator['EmailSmtpport']);
			unset($validator['EmailSmtpuser']);
			unset($validator['EmailSmtppassword']);
			unset($validator['EmailNotifyUser']);
		}
		if (!empty($authGroups)) {
			foreach ($authGroups as $userRole => $authInfo) {
				$userGuid = null;
				if ($authInfo['prefix'] === 'admin') {
					$userGuid = $this->getUserGuid();
				}
				$fieldName = $authInfo['field'];
				$validator[$fieldName] = [
					'valid_group_' . $fieldName => [
						'rule' => ['validGroup', $userGuid],
						'message' => __d('cake_settings_app_validation_errors', 'This field must contain a valid group name.'),
						'required' => true,
						'allowEmpty' => false,
					]
				];
			}
		}

		return true;
	}
737538
public final function validate(array $data = null, array $rules = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if (empty($data)) {
			throw new ValidateException(['error' => 'data is empty']);
		}
		if ($rules) {
			$this->rules    = [];
			$this->rulesIdx = [];
			$this->ruleKeys = [];
			foreach ($rules as $field => $rule) {
				$this->addRule($field, $rule);
			}
		}

		return $this->validateNewData($data);
	}
1024802
public function addRules($rules)
    {
        // The primary purpose of this parser is to expand any "*" rules to the all
        // of the explicit rules needed for the given data. For example the rule
        // names.* would get expanded to names.0, names.1, etc. for this data.
        $response = (new ValidationRuleParser($this->data))
                            ->explode($rules);

        $this->rules = array_merge_recursive(
            $this->rules, $response->rules
        );

        $this->implicitAttributes = array_merge(
            $this->implicitAttributes, $response->implicitAttributes
        );
    }
402049
protected function parseRules(array $rules)
    {
        $parsedRules = [];

        foreach ($rules as $attribute => $filters) {
            if (empty($filters)) {
                throw new InvalidFilterException(
                    "The attribute [$attribute] must contain at least one filter."
                );
            }

            $this->parseAttributeFilters($parsedRules, $attribute, $filters);
        }

        return $parsedRules;
    }
911881
protected function validate(array $rules, bool $throwError = true)
    {
        $validations = [];
        $data = [];
        foreach ($rules as $key => $rule) {
            $value = $this->request->get($key);
            $violations = $this->validator->validate($value, $rule);
            if (count($violations) > 0) {
                $validations[$key] = [];
                foreach ($violations as $violation) {
                    $validations[$key][] = $violation->getMessage();
                }
            } else {
                $data[$key] = $value;
            }
        }
        if ($throwError && count($validations)) {
            throw new HttpValidationException($validations);
        }
        return $data;
    }
1349460
private function addDefaultPreviewRule(?array $scopeRules, array $defaultRule): array
    {
        $scopeRules = is_array($scopeRules) ? $scopeRules : [];

        $contentBrowserRules = $scopeRules['ngcb_preview'] ?? [];

        $contentBrowserRules += [
            '___ngcb_preview_default___' => $defaultRule,
        ];

        $scopeRules['ngcb_preview'] = $contentBrowserRules;

        return $scopeRules;
    }
1287395
public function rules(): array
    {
        $manager = $this->route('manager') ?? app('cortex.auth.manager');

        // Attach attribute rules
        $manager->getEntityAttributes()->each(function ($attribute, $attributeName) use (&$rules) {
            switch ($attribute->type) {
                case 'datetime':
                    $type = 'date';
                    break;
                case 'text':
                case 'check':
                case 'select':
                case 'varchar':
                    $type = 'string';
                    break;
                default:
                    $type = $attribute->type;
                    break;
            }

            $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type;
            $rules[$attributeName.($attribute->is_collection ? '.*' : '')] = $rule;
        });

        return $rules ?? [];
    }