调度

@param string $rule
@throws Exception
483473
public static function exec($rule = null, $pageNotFound = true)
	{
		self::switchMCA($rule);
		$params = array('result'=>&$result);
		Event::trigger('YURUN_DISPATCH',$params);
		if($params['result'])
		{
			return;
		}
		// 载入模块配置
		Config::removeInstance('Module');
		Config::create(array(
			'type'	=>	'php',
			'option'	=>	array(
				'filename'	=>	APP_MODULE . self::$module .'/' .Config::get('@.CONFIG_PATH') . '/config.php',
			)
		), 'Module');
		if(
				// 判断域名是否有权限访问
				!self::checkDomain()
				||
				// 判断是否执行成功
				(false===self::call() && $pageNotFound))
		{
			// 页面不存在
			$continue = true;
			$params = array('continue'=>&$continue);
			Event::trigger('YURUN_MCA_NOT_FOUND',$params);
			if($continue)
			{
				Response::msg(Lang::get('PAGE_NOT_FOUND'), null, 404);
			}
		}
	}
664076
public function validate($rule = null)
    {
        if (is_null($rule)) {
            throw $this->exception('Incorrect usage of field validation');
        }

        if (is_string($rule)) {
            // If string is passed, prefix with the field name
            $rule = $this->short_name.'|'.$rule;
        } elseif (is_array($rule)) {
            // if array is passed, prepend with the rule
            array_unshift($rule, $this->short_name);
            $rule = array($rule);
        } elseif (is_callable($rule)) {
            // callable or something else is passed. Wrap into array.
            $rule = array(array($this->short_name, $rule));
        }

        $this->form->validate($rule);

        return $this;
    }
358052
public function apply(Rule $rule, $value)
    {
        //Check for Whitespace support
        $whitespaceChar = ($rule->allowWhitespace)? " ":"";

        $rule->unicodePattern = '/[^\p{N}' . $whitespaceChar . ']/';
        $rule->pattern        = '/[^0-9' . $whitespaceChar . ']/';

        return parent::apply($rule, $value);
    }
598547
public function addRule(Rule $rule)
    {
        $classname = $rule->getClass();
        if ($this->hasRule($classname) === true) {
            throw new Exception(
                "failed to add rule; the field {$this->name} already has an ".
                "instance of '$classname'"
            );
        }
        else if ($classname === Rule::REQUIRED) {
            $this->rules = [$classname => $rule] + $this->rules;
        }
        else {
            $this->rules[$classname] = $rule;
        }
        return $this;
    }
1094342
public function fromForm($rule = 'default', $all = false)
	{
		// 获取规则
		if (! is_array($rule))
		{
			if (isset($this->rules[$rule]))
			{
				$rule = $this->rules[$rule];
			}
			else
			{
				return false;
			}
		}
		// 清空当前数据
		$this->data = array ();
		// 循环获取数据
		foreach ($rule as $value)
		{
			// 规则合法性判断
			if (isset($value['name']))
			{
				// 处理没有传入from的情况
				if (! isset($value['table']))
				{
					$value['table'] = '';
				}
			}
			else
			{
				// 判断数量是否正确
				if (count($value) < 3)
				{
					throw new Exception(Lang::get('MODEL_FORM_ARGS_LESS'));
					break;
				}
				$t = $value;
				$value = array ();
				// 直接传值处理
				$value['name'] = $t[0];
				if (isset($t[3]))
				{
					$value['table'] = $t[3];
				}
				else
				{
					$value['table'] = '';
				}
			}
			// 获取数据
			$d = Request::getAll($value['table'], $value['name']);
			// 判断获取是否成功
			if (false === $d)
			{
				// 判断是否有默认值
				if(array_key_exists('default',$value))
				{
					$this->data[$value['name']] = $value['default'];
				}
			}
			else
			{
				// 过滤器支持
				if(isset($value['filter']))
				{
					$this->data[$value['name']] = execFilter($d,$value['filter']);
				}
				else
				{
					$this->data[$value['name']] = execFilter($d,Config::get('@.DEFAULT_FILTER'));
				}
			}
		}
		// 开始验证
		$v = new Validator();
		// 保存验证结果
		$result = $v->validate($all, $this->data, $rule);
		if (array () === $result)
		{ // 验证通过
		  // 字段映射
			$this->data = $this->parseFieldsMap($this->data);
			return true;
		}
		else
		{
			// 清空数据
			$this->data = array ();
			// 返回验证结果
			return $result;
		}
	}
664196
public function setRules($rules)
    {
        foreach ($rules as $ruleName => $rule) {
            $this->setRule($ruleName, $rule);
        }
    }
813838
public function updateRuleData(Rule $rule): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_rule_data')
            ->set('enabled', ':enabled')
            ->set('priority', ':priority')
            ->where(
                $query->expr()->eq('rule_id', ':rule_id')
            )
            ->setParameter('rule_id', $rule->id, Type::INTEGER)
            ->setParameter('enabled', $rule->enabled, Type::BOOLEAN)
            ->setParameter('priority', $rule->priority, Type::INTEGER);

        $query->execute();
    }
875192
public function apply(Rule $rule, $value)
    {
        //trim() only operates in default mode
        //if no second argument is passed, it
        //cannot be passed as null
        if ($rule->charlist === null) {
            return trim($value);
        }

        return trim($value, $rule->charlist);
    }
804020
public function addRule(string $key, string $rule) : ValidatorInterface
    {
        $this->rules[$key] = $rule;

        return $this;
    }
1180786
public function check($rule = []) {
		$rule = $rule ?: $this->validate;

		/* 检查文件大小 */
		if (isset($rule['size']) && !$this->checkSize($rule['size'])) {
			$this->error = '上传文件大小不符！';
			return false;
		}

		/* 检查文件Mime类型 */
		if (isset($rule['type']) && !$this->checkMime($rule['type'])) {
			$this->error = '上传文件MIME类型不允许！';
			return false;
		}

		/* 检查文件后缀 */
		if (isset($rule['ext']) && !$this->checkExt($rule['ext'])) {
			$this->error = '上传文件后缀不允许';
			return false;
		}

		/* 检查图像文件 */
		if (!$this->checkImg()) {
			$this->error = '非法图像文件！';
			return false;
		}

		return true;
	}
124542
public function revokeRule($rule)
    {
        if ($this->hasRule($rule)) {
            unset($this->rules[$rule]);
            return true;
        } else {
            return false;
        }
    }
978518
public function onUpdate(string $rule = self::NO_ACTION): AbstractForeignKey
    {
        $this->updateRule = strtoupper($rule);

        return $this;
    }
312752
public final void ruleXAndExpression() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:221:2: ( ( ( rule__XAndExpression__Group__0 ) ) )
            // InternalXbase.g:222:2: ( ( rule__XAndExpression__Group__0 ) )
            {
            // InternalXbase.g:222:2: ( ( rule__XAndExpression__Group__0 ) )
            // InternalXbase.g:223:3: ( rule__XAndExpression__Group__0 )
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getXAndExpressionAccess().getGroup()); 
            }
            // InternalXbase.g:224:3: ( rule__XAndExpression__Group__0 )
            // InternalXbase.g:224:4: rule__XAndExpression__Group__0
            {
            pushFollow(FOLLOW_2);
            rule__XAndExpression__Group__0();

            state._fsp--;
            if (state.failed) return ;

            }

            if ( state.backtracking==0 ) {
               after(grammarAccess.getXAndExpressionAccess().getGroup()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
155931
public function saveRule($rule) {
        $logger = $GLOBALS['logger'];
        $path    = 'rules/create';
        $request = $this->_remoteServer->post(
            $path,
            array('Content-Type'=>'application/json'),
            $rule
        );
        try {
            $response = $request->send();
            if ($response->getStatusCode() !== 200) {
                throw new \Exception('Unable to handle request');
            }
            $rawResponse = $response->getBody('true');
            return $rawResponse;
        } catch (\Exception $e) {
            throw $e; 
        }
        
    }
277873
public static function parseDotRule($rule)
    {
        $result = preg_split('#(?<!\\\)\.#', $rule);
        array_walk($result, function(&$value, $key){
            if(false !== strpos($value,'\.'))
            {
                $value = str_replace('\.', '.', $value);
            }
        });
        return $result;
    }
587601
public function removeRule($configuration, RuleInterface $rule)
    {
        $current = $this->getConfiguredRule($configuration, $rule);
        if ($current !== '') {
            $configuration = str_replace(array("\r\n", "\r"), "\n", (string) $configuration);
            $configuration = trim(str_replace($current, "\n\n", $configuration));
            if ($configuration !== '') {
                $configuration .= "\n";
            }
        }

        return $configuration;
    }
168149
public function delPermissionBatch($condition)
    {
        $model = new Permission($this->db);
        if ($model->where($condition)->delete() === false) {
            throw new Exception('批量删除数据出错');
        }
        return true;
    }