收集当前场景可用的规则列表
Collect the current scenario of the available rules list
@throws \InvalidArgumentException
767111
protected function collectRules()
    {
        $scene = $this->scene;

        foreach ($this->getRules() as $rule) {
            // check fields
            if (!isset($rule[0]) || !$rule[0]) {
                throw new \InvalidArgumentException('Please setting the fields(string|array) to wait validate! position: rule[0].');
            }

            // check validator
            if (!isset($rule[1]) || !$rule[1]) {
                throw new \InvalidArgumentException('The rule validator is must be setting! position: rule[1].');
            }

            // only use to special scene.
            if (!empty($rule['on'])) {
                if (!$scene) {
                    continue;
                }

                $sceneList = \is_string($rule['on']) ? Filters::explode($rule['on']) : (array)$rule['on'];

                if (!\in_array($scene, $sceneList, true)) {
                    continue;
                }

                unset($rule['on']);
            }

            $this->_usedRules[] = $rule;
            // fields
            $fields = \array_shift($rule);
            $this->prepareRule($rule);

            yield $fields => $rule;
        }
        //
    }
903854
public function filteringScenarios()
    {
        $scenarios = [ActiveRecord::SCENARIO_DEFAULT => []];
        foreach ($this->getFilterValidators() as $validator) {
            foreach ($validator->on as $scenario) {
                $scenarios[$scenario] = [];
            }
            foreach ($validator->except as $scenario) {
                $scenarios[$scenario] = [];
            }
        }
        $names = array_keys($scenarios);

        foreach ($this->getFilterValidators() as $validator) {
            if (empty($validator->on) && empty($validator->except)) {
                foreach ($names as $name) {
                    foreach ($validator->attributes as $attribute) {
                        $scenarios[$name][$attribute] = true;
                    }
                }
            } elseif (empty($validator->on)) {
                foreach ($names as $name) {
                    if (!in_array($name, $validator->except, true)) {
                        foreach ($validator->attributes as $attribute) {
                            $scenarios[$name][$attribute] = true;
                        }
                    }
                }
            } else {
                foreach ($validator->on as $name) {
                    foreach ($validator->attributes as $attribute) {
                        $scenarios[$name][$attribute] = true;
                    }
                }
            }
        }

        foreach ($scenarios as $scenario => $attributes) {
            if (!empty($attributes)) {
                $scenarios[$scenario] = array_keys($attributes);
            }
        }

        foreach ([ActiveRecord::SCENARIO_CREATE, ActiveRecord::SCENARIO_UPDATE] as $scenario) {
            if (!isset($scenarios[$scenario])) {
                $scenarios[$scenario] = $scenarios[ActiveRecord::SCENARIO_DEFAULT];
            }
        }
        return $scenarios;
    }
52299
public function valid()
    {
        if (null === $this->getManagerName()) {
            $errMsg = 'No workflow manager';
            throw new Exception\InvalidArgumentException($errMsg);
        }

        if (null === $this->getActionName()) {
            $errMsg = 'Not Specified action for workflow';
            throw new Exception\InvalidArgumentException($errMsg);
        }

        $workflowActivity = $this->getRunType();
        if (!array_key_exists($workflowActivity, $this->allowWorkflowRunType)) {
            $errMsg = sprintf('Invalid activity %s', $workflowActivity);
            throw new Exception\InvalidArgumentException($errMsg);
        }

        if (static::WORKFLOW_RUN_INITIALIZE === $workflowActivity && null === $this->getWorkflowName()) {
            $errMsg = 'Not specified name workflow';
            throw new Exception\InvalidArgumentException($errMsg);
        }

        if (static::WORKFLOW_RUN_TYPE_DO_ACTION === $workflowActivity && null === $this->getEntryId()) {
            $errMsg = 'Not specified entryId';
            throw new Exception\InvalidArgumentException($errMsg);
        }
    }
590782
public <RO> SingleRuleContext<DPO, Collection<DPO>, RO> check(Collection<Rule<Collection<DPO>, RO>> rules) {
        List<Rule<Collection<DPO>, RO>> addedRules = new ArrayList<Rule<Collection<DPO>, RO>>();
        if (rules != null) {
            addedRules.addAll(rules);
        }

        // Change context
        return new SingleRuleContext<DPO, Collection<DPO>, RO>(addedTriggers, addedDataProviders,
                GeneralValidator.MappingStrategy.JOIN, null, addedRules);
    }
972956
public function rules()
    {
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
        $user = $this->route('auth_user');

        return array_merge(parent::rules(), [
            'username'              => ['required', 'string', 'min:3', $this->getUsernameRule()->ignore($user->id)],
            'email'                 => ['required', 'string', 'email', $this->getEmailRule()->ignore($user->id)],
            'password'              => ['nullable', 'string', 'required_with:password_confirmation', 'min:8', 'confirmed'],
            'password_confirmation' => ['nullable', 'string', 'required_with:password'],
        ]);
    }
1227690
private function validateFields()
    {
        $fields = (array) $this->fields;

        if (empty($fields)) {
            throw new Exception\InvalidArgumentException('Provided fields list was empty!');
        }

        foreach ($fields as $key => $field) {
            if (! is_string($field)) {
                throw new Exception\InvalidArgumentException(
                    sprintf('Provided fields must be strings, %s provided for key %s', gettype($field), $key)
                );
            }
        }

        $this->fields = array_values($fields);
    }
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;
	}
1313066
public <RO> MultipleRuleContext<DPO, TDPO, RO> check(Collection<Rule<TDPO, RO>> rules) {
        List<Rule<TDPO, RO>> addedRules = new ArrayList<Rule<TDPO, RO>>();
        if (rules != null) {
            addedRules.addAll(rules);
        }

        // Change context
        return new MultipleRuleContext<DPO, TDPO, RO>(addedTriggers, addedDataProviders, dataProviderToRuleMapping,
                addedRuleInputTransformers, addedRules);
    }
938146
public function getValidationRules()
    {
        $rules = [];

        foreach ($this->rules as $name => $rule) {
            $ruleName         = sprintf('2fa.*.settings.%s', $name);
            $rules[$ruleName] = $rule;
        }

        return $rules;
    }
51612
protected function validate()
    {
        if (!in_array($this->operation, self::$allowedOperations, true)) {
            throw new InvalidArgumentException('Unsupported condition operation');
        }

        if (!is_array($this->value) && $this->isArrayOperation()) {
            throw new InvalidArgumentException('Value is not of type array');
        }

        if (is_array($this->value) && $this->isRangeOperation() && count($this->value) < 2) {
            throw new InvalidArgumentException('Wrong number of values for range');
        }
    }
539018
public function getRule()
    {
        $rules = [];
        if ($this->isRequired()) {
            $rules[] = 'required';
        }
        if ($this->getValidations()) {
            $rules[] = $this->getValidations();
        }

        $rules = join('|', $rules);
        return $rules;
    }
1287260
public function getModelValidationMessages()
    {
        $optionsMessages = $this->getOption('messages');

        //if the 'rules' option was provided for this model, it takes precedent
        if (is_array($optionsMessages)) {
            return $optionsMessages;
        }

        //otherwise look for the messages as a static property on the model
        return $rules = $this->getModelStaticValidationMessages() ?: array();
    }
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();
	}
217239
@Before()
    public void beforeScenario(Scenario scenario) {
        getContext().setHar(HarContext.getInstance().getServer().newHar(scenario.getName()));
    }
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());
    }
1190947
public function getRuleList()
    {
        $rows = (new Query())
            ->select(['name'])
            ->from($this->manager->ruleTable)
            ->all();

        return ArrayHelper::map($rows, 'name', 'name');
    }
807794
def get_rules(scenario_id, **kwargs):
    
    rules = db.DBSession.query(Rule).filter(Rule.scenario_id==scenario_id, Rule.status=='A').all()

    return rules