读取路由
@access public
@param  string $rule 路由规则
@param  string $domain 域名
@return array
173659
public function getRule($rule, $domain = null)
    {
        if (is_null($domain)) {
            $domain = $this->domain;
        }

        return $this->app['rule_name']->getRule($rule, $domain);
    }
514714
public function getAll( $domain )
	{
		$messages = [];

		foreach( $this->getTranslations( $domain ) as $object ) {
			$messages = $messages + $object->all();
		}

		return $messages;
	}
427528
public function getAllByLocaleAndDomain($locale, $domain)
    {
        return $this->createQueryBuilder('tu')
            ->select('tu, te')
            ->leftJoin('tu.translations', 'te')
            ->where('tu.domain = :domain')
            ->andWhere('te.locale = :locale')
            ->setParameter('domain', $domain)
            ->setParameter('locale', $locale)
            ->getQuery()
            ->getArrayResult();
    }
1189200
public function parseRule($rule, $route, $url, $option = [], $matches = [])
    {
        if (is_string($route) && isset($option['prefix'])) {
            // 路由地址前缀
            $route = $option['prefix'] . $route;
        }

        // 替换路由地址中的变量
        if (is_string($route) && !empty($matches)) {
            foreach ($matches as $key => $val) {
                if (false !== strpos($route, '<' . $key . '>')) {
                    $route = str_replace('<' . $key . '>', $val, $route);
                } elseif (false !== strpos($route, ':' . $key)) {
                    $route = str_replace(':' . $key, $val, $route);
                }
            }
        }

        // 解析额外参数
        $count = substr_count($rule, '/');
        $url = array_slice(explode('|', $url), $count + 1);
        $this->parseUrlParams(implode('|', $url), $matches);

        $this->vars = $matches;
        $this->option = $option;
        $this->doAfter = true;
        
        // 发起路由调度
        return ['route' => $route, 'option' => $option,'param' => $this->getVars()];
    }
1342937
private function parseRule($rule) {
		$parsed = [false];
		if (preg_match('#^([a-z][a-z\d_]+)\s*\((.+)\)\s*$#i', $rule, $ms)) {
			$method = trim($ms[1]);
			$ops    = trim($ms[2]);
		} else {
			$method = trim($rule);
			$ops    = '';
		}
		$parsed[0] = $method;
		$parsed[1] = $ops;

		return $parsed;
	}
235815
public function configureRule(Rule $rule)
    {
        if ($config = $this->getRuleConfig($rule)) {
            
            if (isset($config['type'])) {
                $rule->setType($config['type']);
            }
            
            if (isset($config['format'])) {
                $rule->setFormat($config['format']);
            }
            
            if (isset($config['attribute'])) {
                $rule->setAttribute($config['attribute']);
            }
            
        }
        
        return $rule;
    }
1042620
public function parseGroupRule($rule)
    {
        $origin = $this->router->getGroup();
        $this->router->setGroup($this);

        if ($rule instanceof \Closure) {
            Container::getInstance()->invokeFunction($rule);
        } elseif (is_array($rule)) {
            $this->addRules($rule);
        } elseif (is_string($rule) && $rule) {
            $this->router->bind($rule, $this->domain);
        }

        $this->router->setGroup($origin);
    }
550581
protected function getValidatorType( $key, $rule )
	{
		// 判断验证类型
		if( !is_numeric( $key ) ){
			return [$key, $rule, $key];
		}
		if( strpos( $rule, ':' ) ){
			list( $type, $rule ) = explode( ':', $rule, 2 );
			if( isset( $this->alias[$type] ) ){
				// 判断别名
				$type = $this->alias[$type];
			}
			$info = $type;
		} elseif( method_exists( $this, $rule ) ){
			$type = $rule;
			$info = $rule;
			$rule = '';
		} else{
			$type = 'is';
			$info = $rule;
		}
		return [$type, $rule, $info];
	}
1012642
private function _parseParams($rule)
    {
        $parsed = array();

        $split = explode("(", $rule);
        $name = $split[0];
        $str_params = rtrim($split[1], ")");
        // if empty string
        if ($str_params == '')
        {
            $parsed_params = array();
        }
        else
        {
            $parsed_params = explode(",", $str_params);
        }
        $parsed["params"] = $parsed_params;
        $parsed["name"] = $name;

        return $parsed;
    }
1262137
public function parse($value, $rule) {

        $default = isset($rule['default']) ? $rule['default'] : NULL;
        $index = $rule['name'];
        $fileList = array();

        // 未上传 && (有默认值 || 非必须)
        if (!isset($_FILES[$index]) && ($default !== NULL || empty($rule['require']))) {
            return $default;
        }

        if (!isset($_FILES[$index]) || !is_array($_FILES[$index])) {
            $message = isset($rule['message'])
                ? \PhalApi\T($rule['message'])
                : \PhalApi\T('miss upload file: {file}', array('file' => $index));
            throw new BadRequestException($message);
        }

        if (is_array($_FILES[$index]['tmp_name'])) {
            $count = sizeof($_FILES[$index]['tmp_name']);

            for ($i = 0; $i < $count; $i++) {
                $file = array(
                    'name' => $_FILES[$index]['name'][$i],
                    'type' => $_FILES[$index]['type'][$i],
                    'tmp_name' => $_FILES[$index]['tmp_name'][$i],
                    'error' => $_FILES[$index]['error'][$i],
                    'size' => $_FILES[$index]['size'][$i]
                );

                $fileList[] = $this->parseOne($file, $rule);
            }
        } else {
            $file = array(
                'name' => $_FILES[$index]['name'],
                'type' => $_FILES[$index]['type'],
                'tmp_name' => $_FILES[$index]['tmp_name'],
                'error' => $_FILES[$index]['error'],
                'size' => $_FILES[$index]['size']
            );
            // 单个文件直接返回文件信息数组
            return $this->parseOne($file, $rule);
        }

        // 返回文件信息二维数组
        return $fileList;
    }
768457
public static function url($rule = null, $param = null, $subDomain = null, $noEvent = false, $scheme = '')
	{
		// 支持数组和文本两种数据格式
		if(empty($param))
		{
			$param = array();
		}
		else if(is_string($param))
		{
			parse_str($param, $param);
		}
		if(empty($rule))
		{
			$rule = self::$module . '/' . self::$control . '/' . self::$action;
		}
		if(!$noEvent)
		{
			// 事件处理
			$args = array('rule'=>$rule, 'param'=>$param, 'subDomain'=>$subDomain, 'result'=>&$result);
			Event::trigger('YP_URL_CREATE',$args);
			if (!empty($result))
			{
				return $result; // 返回事件处理结果
			}
		}
		unset($args,$result);
		// 解析url
		$urlInfo = parse_url($rule);
		// 处理参数
		if(!empty($urlInfo['query']))
		{
			parse_str($urlInfo['query'], $tmpParam);
			$param = array_merge($tmpParam,$param);
			unset($tmpParam);
		}
		// 处理path
		try {
			$mca = explode('/', isset($urlInfo['path'][1]) && '/' === $urlInfo['path'][1] ? substr($urlInfo['path'], 1) : $urlInfo['path']);
		} catch (Exception $e) {
		}
		if(isset($mca[2])) // 3个成员
		{
			$module = ucfirst($mca[0]);
			$control = ucfirst($mca[1]);
			$action = $mca[2];
		}
		else if(isset($mca[1])) // 2个成员
		{
			$module = self::$module;
			$control = ucfirst($mca[0]);
			$action = $mca[1];
		}
		else if(isset($mca[0]) && '' !== $mca[0]) // 1个成员
		{
			$module = self::$module;
			$control = self::$control;
			$action = $mca[0];
		}
		else // 为空时
		{
			$module = self::$module;
			$control = self::$control;
			$action = self::$action;
		}
		unset($mca);
		$path = "{$module}/{$control}/{$action}";
		// 根据路由规则判断
		$urlPath = self::parseUrlRoute($path,$param,$filename);
		// 文件名
		if(Config::get('@.route.hide_default_file') && $filename === Config::get('@.route.default_file'))
		{
			$filename = '';
		}
		if(false === $urlPath)
		{
			// 没有开启路由或没有匹配到路由
			if(Config::get('@.PATHINFO_ON') || Config::get('@.URL_PARSE_ON'))
			{
				// PATHINFO
				$urlPath = $path;
			}
			else if(Config::get('@.QUERY_PATHINFO_ON'))
			{
				// URL路由解析
				$param[Config::get('@.PATHINFO_QUERY_NAME')] = $path;
			}
			else
			{
				// 传统
				$param[Config::get('@.MODULE_NAME')] = $module;
				$param[Config::get('@.CONTROL_NAME')] = $control;
				$param[Config::get('@.ACTION_NAME')] = $action;
			}
		}
		// 协议，http、https……
		if('' === $scheme)
		{
			if(isset($urlInfo['scheme']))
			{
				$protocol=$urlInfo['scheme'] . '://';
			}
			else
			{
				$protocol = Config::get('@.URL_PROTOCOL');
				if(empty($protocol))
				{
					$protocol=Request::getProtocol();
				}
			}
		}
		else
		{
			$protocol = $scheme;
		}
		// 域名
		if(isset($urlInfo['host']))
		{
			$domain = $urlInfo['host'];
		}
		else
		{
			$domain = Config::get('@.DOMAIN');
			if(empty($domain))
			{
				$domain = $_SERVER['HTTP_HOST'] . strtr(dirname($_SERVER['SCRIPT_NAME']), '\\','/');
			}
		}
		// 子域名
		if(is_string($subDomain))
		{
			$domain = $subDomain . '.' . $domain;
		}
		// 去除域名后尾的/
		if('/' === substr($domain,-1,1))
		{
			$domain = substr($domain,0,-1);
		}
		if(!empty($param))
		{
			if(false === strpos($urlPath,'?'))
			{
				$query = '?' . http_build_query($param);
			}
			else
			{
				$query = '&' . http_build_query($param);
			}
		}
		// 锚点支持
		if(isset($urlInfo['fragment']))
		{
			$fragment = '#' . $urlInfo['fragment'];
		}
		else 
		{
			$fragment = '';
		}
		if('' !== $filename && $filename !== null)
		{
			$filename .= '/';
		}
		$url = "{$protocol}{$domain}/{$filename}{$urlPath}{$query}{$fragment}";
		return $url;
	}
1346125
protected function getValueFromRule($rule)
    {
        $value = $this->getRuleValue($rule);

        if (isset($this->operators[$rule->operator]['accept_values'])
            && $this->operators[$rule->operator]['accept_values'] === false) {
            return $this->operatorValueWhenNotAcceptingOne($rule);
        }

        return $this->getCorrectValue($rule->operator, $rule, $value);
    }
212288
protected function getUsers(array $data, string $domain): array
    {
        /**
         * @var \CakeDC\Users\Model\Table\UsersTable $table
         */
        $table = $this->getUsersTable();

        $result = [];
        for ($i = 0; $i < $data['count']; $i++) {
            $username = $data[$i]['userprincipalname'][0];
            $username = str_replace('@' . $domain, '', $username);

            $query = $table->find()->where(['username' => $username]);
            if ($query->isEmpty()) {
                continue;
            }

            $result[] = $query->first();
        }

        return $result;
    }
734746
public function retrieve($domain)
	{
		$messages = $this->session->get($this->key($domain), array());

		if (count($messages))
		{
			$this->clear($domain);
		}

		return $messages;
	}
1368711
public function getRuleList($domain = null)
    {
        $list = [];

        foreach ($this->rule as $ruleDomain => $rules) {
            foreach ($rules as $rule => $items) {
                foreach ($items as $item) {
                    $val['domain'] = $ruleDomain;

                    foreach (['method', 'rule', 'name', 'route', 'pattern', 'option'] as $param) {
                        $call = 'get' . $param;
                        $val[$param] = $item->$call();
                    }

                    $list[$ruleDomain][] = $val;
                }
            }
        }

        if ($domain) {
            return isset($list[$domain]) ? $list[$domain] : [];
        }

        return $list;
    }
1072673
public function update($rule)
    {
        $ruleId = "";

        if (is_array($rule)) {
            $ruleId = $rule["id"];
            unset($rule["id"]);
        }
        elseif (is_object($rule)) {
            $ruleId = $rule->id;
            unset($rule->id);
        }

        return $this->client->put("/validation-rules/" . rawurlencode($ruleId), $rule);
    }
992293
public function domain($name, $rule = '', $option = [], $pattern = [])
    {
        // 支持多个域名使用相同路由规则
        $domainName = is_array($name) ? array_shift($name) : $name;

        if ('*' != $domainName && false === strpos($domainName, '.')) {
            $domainName .= '.' . $this->request->rootDomain();
        }

        if (!isset($this->domains[$domainName])) {
            $domain = (new Domain($this, $domainName, $rule, $option, $pattern))
                ->lazy($this->lazy)
                ->mergeRuleRegex($this->mergeRuleRegex);

            $this->domains[$domainName] = $domain;
        } else {
            $domain = $this->domains[$domainName];
            $domain->parseGroupRule($rule);
        }

        if (is_array($name) && !empty($name)) {
            $root = $this->request->rootDomain();
            foreach ($name as $item) {
                if (false === strpos($item, '.')) {
                    $item .= '.' . $root;
                }

                $this->domains[$item] = $domainName;
            }
        }

        // 返回域名对象
        return $domain;
    }