批量注册路由规则
@access public
@param  array $rules 路由规则
@param  string $method 请求类型
@param  array $option 路由参数
@param  array $pattern 变量规则
@return void
490757
public function addRules($rules, $method = '*', $option = [], $pattern = [])
    {
        foreach ($rules as $key => $val) {
            if (is_numeric($key)) {
                $key = array_shift($val);
            }

            if (is_array($val)) {
                $route = array_shift($val);
                $option = $val ? array_shift($val) : [];
                $pattern = $val ? array_shift($val) : [];
            } else {
                $route = $val;
            }

            $this->addRule($key, $route, $method, $option, $pattern);
        }
    }
3276
private function recurse($method, array $data = [], array $rules = [], array $messages = [])
    {
        // Make sure method is valid
        if ( ! in_array($method, ['save', 'validate'])) return false;

        // Disable validation
        $validateBeforeSave = $this->validateBeforeSave;
        $this->validateBeforeSave = false;

        // Perform action
        $result = $this->{$method}($data, $rules, $messages);

        // Check for relationships
        $relationships = $this->getRelationships();

        // Recurse into each relationship if we can
        foreach ($relationships as $name => $type)
        {
            $subresult = $this->recurseRelationship($method, $name, $type);

            // If a relationship fails, we fail
            if ( ! $subresult) $result = false;
        }

        // Reset validation
        $this->validateBeforeSave = $validateBeforeSave;

        return $result;
    }
1259862
public static function initPattern($optionName) {

		if (!isset(self::$store["patternSpecific"])) {
			self::$store["patternSpecific"] = array();
		}

		if ((!isset(self::$store["patternSpecific"][$optionName])) || (!is_array(self::$store["patternSpecific"][$optionName]))) {
			self::$store["patternSpecific"][$optionName] = array();
		}

	}
219605
private function setCache($file, $rules)
    {
        $dir = dirname($file);
        if (!file_exists($dir) && !mkdir($dir, 0750, true)) {
            $this->exception('目录创建失败', $dir);
        }
        foreach ($rules as $method => $rule) {
            file_put_contents($file . "$method.php", '<?php return ' . $this->varExport($rule) . ';'); //输出缓存
        }
    }
740735
public function forget($method, $pattern)
    {
        if (strpos($pattern, "{") === false) {
               unset($this->statics[$method][$pattern]);
        } else unset($this->dynamics[$this->getDynamicIndex($method, $pattern)][$pattern]);
    }
994375
public function setRoute($method, $args)
    {
        $pattern = array_shift($args);
        $callable = array_pop($args);

        //包含额外的参数
        if (count($args) > 0) {
            //额外的参数为单独的调用中间件
            foreach ($args as $call) {
                if (!is_callable($call)) {
                    continue;
                }
                $this->invoke($pattern, $call);
            }
        }
        $this->route->register($method, $pattern, $callable);
    }
251069
public function create(array $rules, string $methods = 'GET, POST'): bool
    {
        //规则不可为空
        if (!$rules) {
            return false;
        }

        //生成前置和后置
        $final_rules = ['S' => [], 'D' => [], 'PRE' => [], 'POST' => []];
        if ($this->pre) {
            $pre_id                      = self::$counter['pre']++;
            $pre_rules                   = $this->parse($this->pre, $this->namespaces['pre']);
            $this->pre                   = [];
            $final_rules['PRE'][$pre_id] = $pre_rules;
        }
        if ($this->post) {
            $post_id                       = self::$counter['post']++;
            $post_rules                    = $this->parse($this->post, $this->namespaces['post']);
            $this->post                    = [];
            $final_rules['POST'][$post_id] = $post_rules;
        }

        //生成主规则
        foreach ($rules as $url => $rule) {
            $r      = preg_match_all('/\{(\w+?)\}/', $url, $params); //匹配动态规则
            $params = $params[1];
            if ($r) {
                $url  = '#^' . preg_replace('/\{(\w+?)\}/', '([^\\#/?]*?)', $url) . '$#'; //将{}替换
                $type = 'D';
            } else {
                $type = 'S';
            }
            $final_rules[$type][$url] = [
                'pre'    => $pre_id ?? null,
                'post'   => $post_id ?? null,
                'main'   => $this->parse($rule, $this->namespaces['main']),
                'params' => $params, //动态参数名
            ];
        }
        //解析完后再检查路由是否冲突
        foreach (explode(',', $methods) as $method) {
            $method = strtoupper(trim($method));
            $this->check($final_rules, $method); //检查路由是否冲突
            if (isset(self::$rules[$method])) {
                foreach ($final_rules as $type => $value) {
                    self::$rules[$method][$type] = self::$rules[$method][$type] + $value; //用+保持索引
                }
            } else {
                self::$rules[$method] = $final_rules;
            }
        }
        return true;
    }
1193799
public function open(array $options = array(), $rules = null)
	{
		$this->setValidation($rules);
		
		return parent::open($options);
	}
760749
public function addRule($rule = '', $action = '', $method = RouteMethod::ANY)
    {
        $method = empty($method) ? RouteMethod::ANY : strtolower($method);
        if (!isset($this->rule[$method])) {
            $this->rule[$method] = array();
        }
        $this->rule[$method][$rule] = $action;
        return true;
    }
684023
public static function in(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value) {
                continue;
            }
            if (in_array($value, $parameters)) {
                continue;
            }

            $validator->addError($attribute, $rule, ['%values' => implode(', ', $parameters)]);
        }
    }
544553
public function process(array $rules, array $data) {
        
        // If conditionning
        $this->rules[] = new Rule(
            'if_boolean', 
            'if:(\w+)', 
            '<?php if (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
        		'if_condition',
        		'if:(\w+)([!<>=]+)(\w+)',
        		'<?php if (isset($this->data[\'$1\'])){$base = $this->data[\'$1\'];}else{$base = \'$1\';};
        		if (isset($this->data[\'$3\'])){$value = $this->data[\'$3\'];}else{$value = \'$3\';}?>
        		<?php if ($base $2 $value): ?>'
        );
        $this->rules[] = new Rule(
            'ifnot', 
            'ifnot:(\w+)', 
            '<?php if (!isset($this->data[\'$1\']) || !$this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'else', 
            'else', 
            '<?php else: ?>'
        );
        $this->rules[] = new Rule(
            'elseif_boolean', 
            'else:(\w+)', 
            '<?php elseif (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'elseif_condition', 
            'else:(\w+)([!<>=]+)(\w+)', 
            '<?php elseif (((isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 $this->data[\'$3\']) ||
        		((isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 \'$3\') ||
        		((!isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && \'$1\' $2 $this->data[\'$3\']) ||
        		((!isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && \'$1\' $2 \'$3\')): ?>'
        );
        $this->rules[] = new Rule(
            'endif', 
            'endif', 
            '<?php endif; ?>'
        );
        
        // Loops
        $this->rules[] = new Rule(
            'loop', 
            'loop:(\w+)', 
            '<?php foreach ($this->data[\'$1\'] as $element): $this->wrap($element); ?>'
        );
        $this->rules[] = new Rule(
            'endloop', 
            'endloop', 
            '<?php $this->unwrap(); endforeach; ?>'
        );
        
        // Importing
        $this->rules[] = new Rule(
            'import_view', 
            'import:(([^\/\s]+\/)?(.*))', 
            '<?php echo $this->importFile(\'$1\'); ?>'
        );
        
        // Clean variables
        $this->rules[] = new Rule(
            'escape_var', 
            'escape:(\w+)', 
            '<?php $this->showVariable(\'$1\', true); ?>'
        );
        
        // Custom rules
        $this->rules = array_merge($this->rules, $rules);
        
        // Variables
        $this->rules[] = new Rule(
            'variable', 
            '(\w+)', 
            '<?php $this->showVariable(\'$1\'); ?>'
        );
        
        // Arrays
        $this->rules[] = new Rule(
        		'variable_array',
        		'(\w+)\[(\w+)\]',
        		'<?php echo (isset($this->data[\'$1\'][\'$2\'])) ? $this->data[\'$1\'][\'$2\'] : "&#123;$1[$2]&#125"; ?>'
        );
        
        $this->rules[] = new Rule(
        		'variable_array_escape',
        		'escape:(\w+)\[(\w+)\]',
        		'<?php echo htmlentities($this->showVariable(\'$1\')[\'$2\']); ?>'
        );
        
        $this->data = $data;
        $this->stack = array();
        
        foreach ($this->rules as $rule) {
            $this->template = preg_replace('/\{' . $rule->rule() . '\}/', $rule->replacement(), $this->template);
        }
        
        $this->template = '?>' . $this->template;
        
        ob_start();
        eval($this->template);
        return ob_get_clean();
    }
1054461
public function addMissRule($route, $method = '*', $option = [])
    {
        // 创建路由规则实例
        $ruleItem = new RuleItem($this->router, $this, null, '', $route, strtolower($method), $option);

        $this->miss = $ruleItem;

        return $ruleItem;
    }
706309
private function select2($fields = false, $where = null, $orderBy = null, $limit = null): array
    {
        //合并请求参数
        $statement = $this->statement;
        $statement->select($fields, $where, $orderBy, $limit);

        // 执行前置 钩子
        $ret = $this->before('Select', $statement);
        if ($ret === self::INTERRUPT) {
            return [];
        }

        //修正查询参数
        list($this->statement) = $ret;

        // 查询结果
        $ret = self::query2();

        // 清除Statement缓存
        $this->clear();

        // 执行后置钩子
        return $this->after('Select', $ret);
    }
434835
public function groupAllowed($alias, $pattern, $method = 'all')
    {
        if (isset($this->group[$alias])) {
            return false;
        }

        $rule = $this->group[$alias];
        return $rule->isAllowed($pattern, $method);
    }
381562
public function match(array $methods, string $pattern, $handler)
    {
        $this['route.collector']->addRoute($methods, $pattern, $handler);
    }
599080
public function when($pattern, $name, $methods = null)
	{
		if ( ! is_null($methods)) $methods = array_map('strtoupper', (array) $methods);

		$this->patternFilters[$pattern][] = compact('name', 'methods');
	}
447558
public function put($rule, $route = '', array $option = [], array $pattern = [])
    {
        return $this->rule($rule, $route, 'PUT', $option, $pattern);
    }