生成URL

@param string $rule
@param array $param
@param mixed $subDomain 子域名前缀
@param bool	$noEvent 是否强制不触发生成事件，默认为false
@return type
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;
	}
673113
function triggerModeScriptEvent($event, $params = '', $multicall = false)
    {
        if (!is_string($event)) {
            throw new InvalidArgumentException('event name must be a string: event = ' . print_r($event, true));
        }

        if (is_string($params)) {
            return $this->execute(ucfirst(__FUNCTION__), array($event, $params), $multicall);
        }

        if (is_array($params)) {
            foreach ($params as $param) {
                if (!is_string($param)) {
                    throw new InvalidArgumentException('argument must be a string: param = ' . print_r($param, true));
                }
            }
            return $this->execute(ucfirst(__FUNCTION__) . 'Array', array($event, $params), $multicall);
        }

        // else
        throw new InvalidArgumentException('argument must be string or string[]: params = ' . print_r($params, true));
    }
1202889
public static function create($sub_app_id, $params, $options = null)
    {
        $url = static::classUrlWithSubAppId($sub_app_id);
        return static::_directRequest('post', $url, $params, $options);
    }
575586
function createRule(path, handler) {
  if ('*' !== path && 0 != path.indexOf(watch.__base)) {
    path = watch.__base + (path == '/' ? '' : path)
  }
  let rule = pathToRegExp(path)
  if (handler instanceof String) {
    let target = handler
    handler = function() {
      watch({
        url: target
      })
    }
  }
  rule.handler = handler

  return rule
}
606686
public function createProxyEvent(Event $event)
    {
        if ($event instanceof GetResponseForControllerResultEvent) {
            $silexEvent = new PostDispatchEvent($event);

        } elseif ($event instanceof GetResponseEvent) {
            $silexEvent = new RequestEvent($event);

        } elseif ($event instanceof FilterControllerEvent) {
            $silexEvent = new PreDispatchEvent($event);

        } elseif ($event instanceof FilterResponseEvent) {
            $silexEvent = new ResponseEvent($event);

        } elseif ($event instanceof SfPostResponseEvent) {
            $silexEvent = new PostResponseEvent($event);

        } elseif ($event instanceof FinishRequestEvent) {
            $silexEvent = new PostRequestEvent($event);

        } elseif ($event instanceof KernelEvent) {
            $silexEvent = new SilexKernelEvent($event);

        } elseif ($event instanceof Event) {
            $silexEvent = new SilexEvent($event);

        } else {
            $silexEvent = null; // unknown event
        }

        return $silexEvent;
    }
508523
function createEvent(params, cb) {
  var resourcePath = config.addURIParams("/events", params);
  var method = "POST";
  var data = {
    uid: params.guid,
    timestamp: (new Date().toISOString()),
    details: params.data.msg,
    eventClass: 'APP_STATE',
    eventType: params.data.type,
    eventLevel: 'FATAL',
    env: params.environment,
    domain: params.domain,
    dyno: '',
    appName: params.appname,
    updateBy: ''
  };

  params.resourcePath = resourcePath;
  params.method = method;
  params.data = data;

  mbaasRequest.app(params, cb);
}
194786
public function createUrl($route, $params = [], $ampersand = '&')
    {
        unset($params[$this->routeVar]);
        foreach ($params as $i => $param) {
            ($param === null) && ($params[$i] = '');
        }
        // 锚点处理
        if (isset($params['#'])) {
            $anchor = '#' . $params['#'];
            unset($params['#']);
        } else {
            $anchor = '';
        }
        $route = trim($route, '/');
        foreach ($this->_rules as $i => $rule) {
            if (($url = $rule->createPathInfo($this, $route, $params, $ampersand)) !== false) {
                return $this->getBaseUrl() . '/' . $url . $anchor;
            }
        }
        if ($this->throwNotMatchRule) {
            // 不匹配规则时抛出异常
            throw new Exception(str_cover('创建URL时，路由"{route}"找不到对应的规则，请确认路由或规则是否正确', [
                '{route}' => $route,
            ]), 100900102);
        } else {
            return $this->createUrlDefault($route, $params, $ampersand) . $anchor;
        }
    }
476057
public static function replace_subdomain($url, $newSubdomain)
    {
        $url = parse_url($url);
        if(substr_count($url['host'], '.') >= 2) {
            $url['host'] = (str_replace(
                substr($url['host'], 0, strpos($url['host'], '.')),
                $newSubdomain,
                $url['host']
            ));
        } else {
            $url['host'] = $newSubdomain.'.'.$url['host'];
        }
        return self::unparse_url($url);
    }
1256323
public function bind(string $routing_rule, string $filter, $event) : RouterInterface
    {
        $builder = new RouterNodeBuilder($routing_rule, $filter, $event);
        try{
            $builder->build($this->root_node);
        }
        catch(RouterNodeBuilderException $e){
            throw new RoutingRuleBindingException($routing_rule, $e);
        }
        return $this;
    }
480526
protected function validate_valid_url($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!filter_var($input[$field], FILTER_VALIDATE_URL)) {
            return array(
                'field' => $field,
                'value' => $input[$field],
                'rule' => __FUNCTION__,
                'param' => $param,
            );
        }
    }
226274
public function handleUrl($url, UserEvent $event, EventQueue $queue)
    {
        $parsedUrl = parse_url($url);

        if (
            (!isset($parsedUrl['host']) && !isset($parsedUrl['path'])) ||
            (!isset($parsedUrl['host']) && isset($parsedUrl['path']) && $parsedUrl['path'] == '')
           ) {
            return false;
        }

        $requestId = uniqid();
        $this->logDebug('[' . $requestId . ']Found url: ' . $url);

        if (count($parsedUrl) == 1 && isset($parsedUrl['path'])) {
            $url = 'http://' . $parsedUrl['path'] . '/';
            $this->logDebug('[' . $requestId . ']Corrected url: ' . $url);
        }

        if ($this->emitUrlEvents($requestId, $url, $event, $queue) && !$this->hostUrlEmitsOnly) {
            $this->logDebug('[' . $requestId . ']Emitting: http.request');
            $this->emitter->emit('http.request', [$this->createRequest($requestId, $url, $event, $queue)]);
        }

        $this->logDebug('[' . $requestId . ']Emitting: url.host.all');
        $this->emitter->emit('url.host.all', [$url, $event, $queue]);

        return true;
    }
557563
public function createSignature($nonceStr, $time, $url) {
        $str = "jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s";
        $result = sprintf($str, $this->getJsApiTicket()->getTicket(), $nonceStr, $time, $url);
        return sha1($result);
    }
400900
public function _buildUrl($path = "", $queryStrings = [], $domain = "")
    {
        $queryString = "";
        foreach ($queryStrings as $key => $value) {
            if (is_array($value)) {
                continue;
            }

            $queryString .= "&{$key}={$value}";
        }
        if (strlen($queryString) > 0) {
            $queryString = "?" . substr($queryString, 1);
        }

        if ($domain == "") {
            $domain = $this->options['base_uri'];
        }

        $path = "/" . trim($path, "/") . "/";

        return "{$domain}{$this->domain}/{$this->options['version']}{$path}{$queryString}";
    }
1081874
public function forceNext ($url, $rule = self::NEXT_FORWARD) {
		$this->rule->next[0][0] = $url;
		$this->rule->next[0][1] = $rule;
	}
1248461
public function addEvent($event, $eventParams)
    {
        // check if valid rule usage for object_type_id
        $this->validateRule("Events", $event);
        // get required parameters for specific rule
        $requiredParams = Events::GetRequiredParams($event);
        // checking for missing and invalid types for each parameter
        $check_params = $this->_checkParams($requiredParams, $eventParams);
        // if no missing or invalid rule parameters
        if ($check_params)
        {
            $value = $this->_formatParams($eventParams);
            $rule = $event . "(" . $value . ")";
            $this->_events[] = $rule;

            return $this->_events;
        }
        return false;
    }
1278564
protected function _createURL($base, $controller, $action, $params, $searchDefined = true)
    {
        $params['controller'] = $controller;
        $params['action'] = $action;
        foreach ($this->urlRoutes as $route => $defined) { // first check those with strict params.
            $cBase = $base;
            $preparedParams = $params;
            if ($searchDefined) {
                if (is_numeric($route)) {
                    continue; // first only get those with defined conditions.
                }
                $match = true;
                foreach ($defined as $def => $value) { // first check if those exact values match.
                    if (($value || '0' === $value) && (!isset($params[$def]) || $params[$def] != $value)) {
                        $match = false;
                    } else {
                        unset($preparedParams[$def]);
                        if ('module' == $def) {
                            if (substr($cBase, -1 * strlen($value . '/')) == $value . '/') { // remove module from base url if it's there
                                $cBase = substr($cBase, 0, strlen($cBase) - strlen($value . '/'));
                            }
                        }
                    }
                }
                if (!$match) {
                    continue;
                }
            }
            $match = true;
            preg_match_all('/\(\?<([a-z0-9_\-]+)>.*?\)/', is_numeric($route) ? $defined : $route, $matches);
            if (!$matches) {
                continue;
            }
            $toReplace = array('\/' => '/');
            foreach ($matches[1] as $k => $word) {
                $match = $match & isset($params[$word]);
                if ($match) {
                    $toReplace[$matches[0][$k]] = $params[$word];
                    unset($preparedParams[$word]);
                } else {
                    break;
                }
            }

            if ($match) {
                unset($preparedParams['module']);
                return $cBase . str_replace(array_keys($toReplace), array_values($toReplace), is_numeric($route) ? $defined : $route) . $this->_params2string($preparedParams) . '.html';
            }
        }
        if ($searchDefined) {
            return $this->_createURL($base, $controller, $action, $params, false);
        }

    }
59546
public static function pass( $event, $param = null ) {
		
		if ( !array_key_exists( $event, static::$events ) ) {
			return $param;
		}
		
		$event = static::$events[$event];
		
		if ( array_key_exists( 'before', $event ) ) {
			$param = static::call( $event['before'], $param, true );
		}
		
		if ( array_key_exists( 'callbacks', $event ) ) {
			$param = static::call( $event['callbacks'], $param, true );
		}
		
		if ( array_key_exists( 'after', $event ) ) {
			$param = static::call( $event['after'], $param, true );
		}
		
		return $param;
	}