检测域名路由
@access public
@param  string       $url      访问地址
@param  bool         $completeMatch   路由是否完全匹配
@return Dispatch|false
967752
public function check($url, $completeMatch = false)
    {
        // 检测别名路由
        $result = $this->checkRouteAlias($url);
        
        if (false !== $result) {
            return $result;
        }

        // 检测URL绑定
        $result = $this->checkUrlBind($url);
        
        if (!empty($this->option['append'])) {
            $request->setRouteVars($this->option['append']);
            unset($this->option['append']);
        }

        if (false !== $result) {
            return $result;
        }

        return parent::check($url, $completeMatch);
    }
1092803
function reroute($url=NULL,$permanent=FALSE,$die=TRUE) {
		if (!$url)
			$url=$this->hive['REALM'];
		if (is_array($url))
			$url=call_user_func_array([$this,'alias'],$url);
		elseif (preg_match('/^(?:@?([^\/()?]+)(?:(\(.+?)\))*(\?.+)*)/',
			$url,$parts) &&
			isset($this->hive['ALIASES'][$parts[1]]))
			$url=$this->hive['ALIASES'][$parts[1]];
		$url=$this->build($url,isset($parts[2])?$this->parse($parts[2]):[]).
			(isset($parts[3])?$parts[3]:'');
		if (($handler=$this->hive['ONREROUTE']) &&
			$this->call($handler,[$url,$permanent,$die])!==FALSE)
			return;
		if ($url[0]!='/' && !preg_match('/^\w+:\/\//i',$url))
			$url='/'.$url;
		if ($url[0]=='/' && (empty($url[1]) || $url[1]!='/')) {
			$port=$this->hive['PORT'];
			$port=in_array($port,[80,443])?'':(':'.$port);
			$url=$this->hive['SCHEME'].'://'.
				$this->hive['HOST'].$port.$this->hive['BASE'].$url;
		}
		if ($this->hive['CLI'])
			$this->mock('GET '.$url.' [cli]');
		else {
			header('Location: '.$url);
			$this->status($permanent?301:302);
			if ($die)
				die;
		}
	}
1238512
protected function _autoCompleteUrl($url) {
		if (mb_strpos($url, '/') === 0) {
			$url = Router::url($url, true);
		} elseif (mb_strpos($url, '://') === false && mb_strpos($url, 'www.') === 0) {
			$url = 'http://' . $url;
		}
		return $url;
	}
853626
public static function action($url) {
        static $prefixes = [];

        $clz = trim($url);
        if (!$clz) {
            return '#';
        }

        $urls = explode('::', $clz);

        $action = '';

        if (count($urls) == 2) {
            $clz    = trim(trim($urls[0]), '\\');
            $action = $urls[1] != 'index' ? $urls[1] : '';
        }

        if (!isset($prefixes[ $clz ])) {
            $clzs    = explode('\\', $clz);
            $id      = $clzs[0];
            $clzs[0] = App::id2dir($id);//将dir转换为dir
            $file    = MODULES_PATH . implode(DS, $clzs) . '.php';
            if (!is_file($file)) {
                return '#';
            } else {
                include_once $file;
                if (!class_exists($clz) || !is_subclass_of($clz, 'wulaphp\mvc\controller\Controller')) {
                    return '#';
                }
            }
            if (($host = App::getModuleDomain($id))) {
                $clzs[0] = '';
            } else {
                $host = null;
            }
            $ctrClz = array_pop($clzs);
            array_pop($clzs);

            $ctr = preg_replace('#Controller$#', '', $ctrClz);
            $ctr = Router::addSlash($ctr);

            if ('index' != $ctr) {
                array_push($clzs, $ctr);
            }

            $prefix = '';
            if (!isset($host) && method_exists($clz, 'urlGroup')) {
                $tprefix = ObjectCaller::callClzMethod($clz, 'urlGroup');
                if ($tprefix && isset($tprefix[0])) {
                    $prefix = $tprefix[0];
                }
            }

            $prefixes[ $clz ] = [$host, $prefix . implode('/', $clzs)];
        }
        if ($action && $action != 'index') {
            return self::url([$prefixes[ $clz ][0], $prefixes[ $clz ][1] . '/' . Router::addSlash($action)], false);
        } else {
            return self::url([$prefixes[ $clz ][0], $prefixes[ $clz ][1]], false);
        }
    }
42635
private function getCompleteUrl($uri = '')
    {
        $uri = $uri === '' ? $this->urlResolver->getPath() : $uri;
        $url = sprintf('%s%s', $this->urlResolver->getDomain(), $uri);

        if ($this->isGet() && $this->GET) {
            $url = sprintf('%s?%s', $url, http_build_query($this->GET->getAll()));
        }

        return $url;
    }
1098227
public function check($url, $must = false)
    {
        // 自动检测域名路由
        $domain = $this->checkDomain();

        $url = str_replace($this->config['app.pathinfo_depr'], '|', $url);

        $completeMatch = $this->config['app.route_complete_match'];

        $result = $domain->check($url, $completeMatch);

        if ($result) {
            $re =  array_merge($result, ['is_route' => true]);
            return $re;
        } elseif ($must) {
            // 强制路由不匹配则抛出异常
            throw new NotFoundHttpException('强制路由,不匹配');
        } else {
            // 检测跨域路由
//            if (!empty($this->cross)) {
//                $result = $this->cross->check($this->request, $url, $completeMatch);
//            }
//
//            if (false !== $result) {
//                // 路由匹配
//                return $result;
//            }

            // 默认路由解析
            $re = new UrlDispatch($this->group, $url, [
                'auto_search' => $this->autoSearchController,
            ]);

            return array_merge($re->init(), ['is_route' => false]);
        }
    }
493701
public static function url($url, $check_url = true) {

        $result = new \sb\Validate\Results();
        $result->value = $url;
        $result->is_valid = false;
        $result->data = new stdClass();

        //  /(\s|\n)([a-z]+?):\/\/([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)/i

        if (preg_match("/^http:\/\/([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)$/i", $url)) {

            $result->message = "Valid url format";
            $result->is_valid = true;

            if ($check_url) {
                $page = @file_get_contents($url);
                if (!$page) {

                    $result->is_valid = false;
                    $result->message .= ' but page not loaded';
                    $result->data->header = $http_response_header[0];
                } else {

                    if (!preg_match("/<html/", $page)) {
                        $result->is_valid = false;
                        $result->message .= " page reachable but no html tag found";
                    } else {
                        $result->message .= " and page loaded";
                    }
                }
            }
        } else {
            $result->message = "Invalid url format";
        }

        return $result;
    }
108175
public function matchUrl($method, $url) {
		if ($this->method == $method) {
			if (preg_match('/^' . $this->url . '$/', $url, $matches)) {
				$params = $this->prepareParams($matches);
				$this->execute($params);
				return true;
			}
			return false;
		}
	}
1218630
public function matchDirectly($url)
    {
        if (!$this->isAcceptedRequestMethod()) {
            return false;
        }

        if (rtrim($this->url, "/") === rtrim($url, "/")) {
            return true;
        }
        return false;
    }
1211095
public static function isUrl(string $url, bool $requiredScheme = false): bool
    {
        $pattern = '#^'.($requiredScheme ? 'https?://' : '((https?:)?//)?').'[a-z0-9]([-a-z0-9\.]*[a-z0-9])?\.[a-z]{2,10}(:\d{1,5})?(/.*)?$#i';

        return preg_match($pattern, $url);
    }
1135497
public static function call($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);

        $result = curl_exec($ch);

        if (! $result) {
            throw new \Exception(sprintf('The endpoint "%s" is not returning anything.', $url));
        }

        return simplexml_load_string($result);
    }
484723
public function match(String $url, bool $strict, bool $case) {

		//If no strict routing, removing last / of $url if $this->path does not have it
		if(!$strict && $this->path[strlen($this->path) - 1] != '/')
			$url = rtrim($url, '/');

		if($case) 	$case = '';
		else 		$case = 'i';

		//Parameters name
		preg_match_all('/{([\w]+)}/', $this->path, $params);
		$params = $params['1'];

		//Replace default regex and brackets
		$path = preg_replace('/{([\w]+)}/', '([^/{}]+)', $this->path);
		$path = str_replace('\{', '{', $path);
		$path = str_replace('\}', '}', $path);

		//Add the regex if needed (regex array and params array not empty)
		$areRegex = !empty($this->regex) || !empty($params);
		if($areRegex) {
			//Explode the path
			$arrayPath = explode('([^/{}]+)', $path);
			$c = count($arrayPath);
			$path = '';

			//Between each '([^/{}]+)' add the path and the regex
			for($i = 0; $i<$c; $i++) {
				$path .= $arrayPath[$i];

				//The end of the path exploded is ""
				if($c-1 != $i) {
					if(isset($this->regex[$i]))
						$path .= $this->preg($this->regex[$i]);
					elseif(empty($this->regex))
						$path .= '([^/{}]+)';
					else
						$path .= $this->preg($this->regex[0]);
				}
			}
		}

		//Create global regex to match url
		$reg = "#^$path$#$case";

		if(!preg_match($reg, $url, $matches))
			return false;

		//Create an array with the parameters name and the value
		$slugs = array();
		if($areRegex) {
			array_shift($matches);
			$c = count($params);

			for($i = 0; $i<$c; $i++) {
				$slugs[$params[$i]] = $matches[$i];
			}
		}

		$this->slugs = $slugs;

		return true;

	}
1257123
public function isMatch($url){

		$url = trim($url);
		if($url == $this->pattern)
			return true;

		$parts = explode("/", trim($url, "/"));
		$pattern = explode("/", trim($this->pattern, "/"));

		if(count($parts) != count($pattern))
			return false;

		// print_r($pattern);

		$regex = array();
		foreach($pattern as $key=>$url_item){

			if(preg_match_all("|{(.*):(.*)}|", $url_item, $matches)){

				if(in_array(reset($matches[2]),  array("int", "bool", "alpha", "float", "date"))){

					switch(reset($matches[2])){

						case "int":
							$regex[] = "[0-9]+";
						break;
						case "bool":
							$regex[] = "(true|false)";
						break;
						case "alpha":
							$regex[] = "[A-Za-z]+";
						break;
						case "float":
							$regex[] = "[+-]?\d+(\.\d+)?";
						break;
						case "date"://yyyy-mm-dd
							$regex[] = "(19?[0-9]{2}|20[0-1][0-4])-(0?[1-9]|1[0-2])-([0-2]?[0-9]|3[0-1])";
						break;
					}

					$this->params[reset($matches[1])] = $parts[$key];
				}
			}
			elseif(preg_match_all("|{(.*)}|", $url_item, $matches)){

				$regex[] = ".*";
				$this->params[reset($matches[1])] = $parts[$key];
			}
			else $regex[] = $url_item;
		}

		return (bool)preg_match(sprintf("/^%s$/", implode("\/", $regex)), trim($url, "/"));
	}
1068819
protected function matchUrlWithParameters($url)
    {
        foreach ($this->routes as $route) {
            if ($route->matchWithParameters($url)) {
                return $route;
            }
        }
        return null;
    }
1356663
private function createFullUrl($url)
    {
        if (is_array($url)) {
            $params = $url;
            if (isset($params[0])) {
                $url = (string)$params[0];
                unset($params[0]);
            } else {
                $url = '';
            }
        }

        if (!empty($this->client->baseUrl)) {
            if (empty($url)) {
                $url = $this->client->baseUrl;
            } elseif (!preg_match('/^https?:\\/\\//i', $url)) {
                $url = rtrim($this->client->baseUrl, '/') . '/' . ltrim($url, '/');
            }
        }

        if (!empty($params)) {
            if (strpos($url, '?') === false) {
                $url .= '?';
            } else {
                $url .= '&';
            }
            $url .= http_build_query($params);
        }

        return $url;
    }
891024
public function removeAction($fullURL, $action = null)
    {
        if (!$action) {
            $action = $this->getAction();    //default to current action
        }
        $returnURL = $fullURL;

        if (($pos = strpos($fullURL, $action)) !== false) {
            $returnURL = substr($fullURL, 0, $pos);
        }

        return $returnURL;
    }
654584
protected function getCurlOptions( $url, $full = false ) {
		$requestType = $this->getRequestType( $url );
		if ( $requestType == "MMS" ) {
			$url = str_ireplace( "mms://", "rtsp://", $url );
		}
		$options = [
			CURLOPT_URL => $url,
			CURLOPT_HEADER => 1,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_AUTOREFERER => true,
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_TIMEOUT => $this->curlTimeoutNoBody,
			CURLOPT_SSL_VERIFYPEER => false,
			CURLOPT_COOKIEJAR => sys_get_temp_dir() . "checkifdead.cookies.dat"
		];
		if ( $requestType == "RTSP" || $requestType == "MMS" ) {
			$header = [];
			$options[CURLOPT_USERAGENT] = $this->mediaAgent;
		} else {
			// Emulate a web browser request but make it accept more than a web browser
			$header = [
				// @codingStandardsIgnoreStart Line exceeds 100 characters
				'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
				// @codingStandardsIgnoreEnd
				'Cache-Control: max-age=0',
				'Connection: keep-alive',
				'Keep-Alive: 300',
				'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
				'Accept-Language: en-us,en;q=0.7,*;q=0.5',
				'Accept-Encoding: *',
				'Pragma: '
			];
			if ( $this->customUserAgent === false ) {
				$options[CURLOPT_USERAGENT] = $this->userAgent;
			} else {
				$options[CURLOPT_USERAGENT] = $this->customUserAgent;
			}
		}
		if ( $requestType == 'FTP' ) {
			$options[CURLOPT_FTP_USE_EPRT] = 1;
			$options[CURLOPT_FTP_USE_EPSV] = 1;
			$options[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_DEFAULT;
			$options[CURLOPT_FTP_FILEMETHOD] = CURLFTPMETHOD_SINGLECWD;
			if ( $full ) {
				// Set CURLOPT_USERPWD for anonymous FTP login
				$options[CURLOPT_USERPWD] = "anonymous:anonymous@domain.com";
			}
		}
		if ( $full ) {
			// Extend timeout since we are requesting the full body
			$options[CURLOPT_TIMEOUT] = $this->curlTimeoutFull;
			$options[CURLOPT_HTTPHEADER] = $header;
			if ( $requestType != "MMS" && $requestType != "RTSP" ) {
				$options[CURLOPT_ENCODING] = 'gzip,deflate';
			}
			$options[CURLOPT_USERAGENT] = $this->userAgent;
		} else {
			$options[CURLOPT_NOBODY] = 1;
		}

		return $options;
	}