检测一个url是否符合给定的匹配规则
@param $pattern  string 匹配规则
@param $url string 匹配规则
@return bool
764707
public function checkUrlMatch($pattern, $url)
    {
        $url = trim($url, '/');
        if (!$url) {
            $url = '/';
        }
        $matcher = $this->getPatternRegexp($pattern);
        if (preg_match($matcher, $url, $matches)) {
            return true;
        }
        return false;
    }
582404
function redirect($pattern,$url,$permanent=TRUE) {
		if (is_array($pattern)) {
			foreach ($pattern as $item)
				$this->redirect($item,$url,$permanent);
			return;
		}
		$this->route($pattern,function($fw) use($url,$permanent) {
			$fw->reroute($url,$permanent);
		});
	}
418692
protected function _checkPcrePattern($pattern = null) {
		if (empty($pattern)) {
			return null;
		}

		$result = true;
		try {
			//@codingStandardsIgnoreStart
			$matchResult = @preg_match($pattern, 'some text');
			//@codingStandardsIgnoreEnd
			if ($matchResult === false) {
				$result = false;
			}
		} catch (Exception $exception) {
			$result = false;
		}

		return $result;
	}
775281
private function matchStripHostsPatterns($url)
    {
        if (Filesystem::isLocalPath($url)) {
            return true;
        }

        if (is_array($this->stripHosts)) {
            $url = trim(parse_url($url, PHP_URL_HOST), '[]');

            if (false !== filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $urltype = 'ipv4';
            } elseif (false !== filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
                $urltype = 'ipv6';
            } else {
                $urltype = 'name';
            }

            if ('ipv4' === $urltype || 'ipv6' === $urltype) {
                $urlunpack = unpack('N*', @inet_pton($url));
            }

            foreach ($this->stripHosts as $pattern) {
                @list($type, $host, $mask) = $pattern;

                if ('/local' === $type) {
                    if ('name' === $urltype && 'localhost' === strtolower($url)
                        || ('ipv4' === $urltype || 'ipv6' === $urltype)
                        && false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)
                    ) {
                        return true;
                    }
                } elseif ('/private' === $type) {
                    if (('ipv4' === $urltype || 'ipv6' === $urltype)
                        && false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)
                    ) {
                        return true;
                    }
                } elseif ('ipv4' === $type || 'ipv6' === $type) {
                    if ($urltype === $type && $this->matchAddr($urlunpack, $host, $mask)) {
                        return true;
                    }
                } elseif ('name' === $type) {
                    if ('name' === $urltype && preg_match($host, $url)) {
                        return true;
                    }
                }
            }
        }
    }
554423
public static function mergeUrlProtocol($url, $protocol = null)
    {
        $protocol   = is_null($protocol) ? static::getProtocol() : $protocol; // 协议类型
        $pattern    = '/^([a-zA-z]+)(:\/\/[^\s]*)/';                           // 正则表达式

        // 执行正则匹配
        preg_match($pattern, $url, $match);

        if ( static::isArray($match) ) {
            if ( isset($match[1]) ) {
                return preg_replace($pattern, $protocol . '$2', $url);
            }
        }

        return $protocol . '://' . $url;
    }
1205974
public function checkWhitelist(string $url): bool
	{
		$pluginSettings = EmbeddedAssets::$plugin->getSettings();
		$whitelist = array_merge($pluginSettings->whitelist, $pluginSettings->extraWhitelist);

		foreach ($whitelist as $whitelistUrl)
		{
			if ($whitelistUrl)
			{
				$pattern = explode('*', $whitelistUrl);
				$pattern = array_map('preg_quote', $pattern);
				$pattern = implode('[a-z][a-z0-9]*', $pattern);
				$pattern = "%^(https?:)?//([a-z0-9\-]+\\.)?$pattern([:/].*)?$%";

				if (preg_match($pattern, $url))
				{
					return true;
				}
			}
		}

		return false;
	}
1291181
public static function verify_site_url($url) {
		$url = trim($url);
		if (!$url || strlen($url) > 64)
			return false;
		return filter_var($url, FILTER_VALIDATE_URL);
	}
683225
public function match($patterns)
    {
        if (!is_array($patterns)) {
            $patterns = [$patterns];
        }

        $url = $this->getUrl();

        foreach ($patterns as $pattern) {
            $pattern = str_replace(['\\*', '\\?'], ['.+', '?'], preg_quote($pattern, '|'));

            if (preg_match('|^'.$pattern.'$|i', $url)) {
                return true;
            }
        }

        return false;
    }
33835
private function matchPattern($pathName, $pattern)
    {
        if ($pattern[0] !== '/') {
            $pattern = '**/' . $pattern;
        }

        if (\fnmatch($pattern, $pathName)) {
            return true;
        }

        return false;
    }
983035
public function isCurrent($page, $pattern)
    {
        // Remove site URL from string
        $page = str_replace($this->getBuilder()->app->getSetting('url'), '', $page);

        return str_is($pattern, $page);
    }
931857
public function rm($pattern = null) {
        if ($pattern) {
            // 指定标签清除
            //$keys = $this->getTagItem($tag);
            $flag = is_array($pattern) && $this->handler->deleteMulti($pattern);
            //$this->rm('tag_' . md5($tag));
            return $flag;
        }
        return $this->handler->flush();
    }
616157
public function match($url = null)
    {
        $match = parent::match($url);
        $regex = $this->getRegex($this->getMatchUrl());

        if ($regex !== ' ') {
            if (preg_match("@" . ltrim($regex) . "@si", $this->getRequestedUrl(), $matches) || true === $match) {
                unset($matches[0]);
                ParameterBag::setParameters($matches);
                return true;
            } else {
                return false;
            }
        } else {
            return 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);
    }
306151
public static function isExternalUrl($url)
    {
        /*
         * Unknown url or it's just slash?
         * Nothing to do
         */
        if (empty($url) || '/' === $url) {
            return false;
        }

        $currentUrl = self::getServerNameOrIp(true);
        $url = self::replenishProtocol($url);

        // Let's prepare pattern of current url
        $search = [
            ':',
            '/',
            '.',
        ];

        $replace = [
            '\:',
            '\/',
            '\.',
        ];

        $currentUrlPattern = str_replace($search, $replace, $currentUrl);

        return !Regex::contains($url, $currentUrlPattern);
    }
771439
public static function isURL($str)
    {
        $pattern = '~^(?:\b[a-z\d.-]+://[^<>\s]+|\b(?:(?:(?:[^\s!@#$%^&*()_=+[\]{}\|;:\'",.<>/?]+)\.)+(?:ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)|(?:(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]))(?:[;/][^#?<>\s]*)?(?:\?[^#<>\s]*)?(?:#[^<>\s]*)?(?!\w))$~iS';

        // Special case that isn't caught by this regex: 'http://' or 'https://' without a domain.
        if (preg_match('~^https?://$~i', $str)) {
            return false;
        }

        return (bool) preg_match($pattern, $str . '/');
    }
714112
public function isEmptyPattern($pattern)
    {
        if (preg_match('/^([A-Za-z]+) +(.*)$/', $pattern, $matches)) {
            $pattern = $matches[2];
        }

        if (trim($pattern) == "") {
            return true;
        }
        return false;
    }
1152576
private static function getPattern(string $pattern)
    {
        $keywords = preg_split("/\\//", $pattern);
        $i = '0';
        $word = "";
        foreach ($keywords as $keyword) {
            $i++;
            if (preg_match("/:/i", $keyword)) {
                $word .= "([a-zA-Z0-9-._]+)";
            } else {
                $word .= $keyword;
            }
            if (count($keywords) != $i) {
                $word .= "/";
            }
        }

        return $word;
    }