Build URL by default route

@param  string $module
@param  string $controller
@param  array  $params

@return string
181543
protected function urlRoute($module, $controller, $params): string
    {
        $url = $this->getBaseUrl();

        if (empty($params) && $controller === self::DEFAULT_CONTROLLER) {
            if ($module === self::DEFAULT_MODULE) {
                return $url;
            }
            return $url . $module;
        }

        $url .= $module . '/' . $controller;
        $getParams = [];
        foreach ($params as $key => $value) {
            // sub-array as GET params
            if (\is_array($value)) {
                $getParams[$key] = $value;
                continue;
            }
            $url .= '/' . urlencode((string)$key) . '/' . urlencode((string)$value);
        }
        if (!empty($getParams)) {
            $url .= '?' . http_build_query($getParams);
        }
        return $url;
    }
1108179
final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) {
        $module = ucfirst(Util::hyphenToCamel($module));
        $moduleOptions = engineGet('config', 'modules', $module, false);
        $module = (isset($moduleOptions['alias'])) ? $moduleOptions['alias'] : $module;

        $return = Util::camelToHyphen($module);
        if ($controller)
            $return .= '/' . Util::camelToHyphen($controller);
        if ($action)
            $return .= '/' . Util::camelToHyphen($action);
        if (!empty($params))
            $return .= str_replace('//', '/' . urlencode(' ') . '/', '/' . join('/', $this->encodeParams($params)));
        if ($hash)
            $return .= '#' . $hash;

        return engineGet('serverPath') . $return;
    }
1177136
protected function getCallParams($controller, $method, $params)
		{
			// variables
			$values     = is_array($params) ? $params : explode('/', $params);
			$ref        = new ReflectionMethod($controller, $method);
			$params     = $ref->getParameters();
			$args       = [];
	
			// map route segments to the method's parameters
			foreach ($params as /** @var \ReflectionParameter */ $param)
			{
				// parse signature [match, optional, type, name, default]
				preg_match('/<(required|optional)> (?:([\\\\a-z\d_]+) )?(?:\\$(\w+))(?: = (\S+))?/i', (string)$param, $matches);
	
				// assign untyped segments
				if ($matches[2] == null)
				{
					$args[$matches[3]] = array_shift($values);
				}
			}
	
			// append any remaining values
			return array_merge($args, $values);
		}
172552
static function ModuleUrl(BackendModule $module, array $args = array())
    {
        $allArgs = array('module'=> ClassFinder::ModuleType($module)) + $args;
        return 'index.php?' . http_build_query($allArgs);
    }
545027
public function getRoute(AdminInterface $admin, $action, $params = [], $isIndex = false)
    {
        $defaults = [];
        $path = '/' . $admin->getAlias();

        // append action if required
        if(!$isIndex) {
            $path .= '/' . $action;
        }

        foreach($params as $paramKey => $paramValue) {
            if(is_int($paramKey)) {
                $paramName = $paramValue;
            }
            else {
                $paramName = $paramKey;
                $defaults[$paramName] = $paramValue;
            }
            $path .= '/{' . $paramName . '}';
        }

        $controller = 'ShuweeAdminBundle:Content:' . $action;

        $defaults = array_merge(
          [
            '_controller' => $controller,
            'alias' => $admin->getAlias(),

          ],
          $defaults
        );

        return new Route($path, $defaults);
    }
106202
public function isValid($module, $controller, $action) {
		if (!in_array($module, $this->modules, true)) {
			return self::ROUTE_ERR_MODULE;
		}
		$className = EntryUtil::controller($module, $controller);
		if (!Container::getInstance()->has($className)) {
			return self::ROUTE_ERR_CONTROLLER;
		}
		$clazz = Container::getInstance()->get($className);
		if (!method_exists($clazz, $action . 'Action')) {
			return self::ROUTE_ERR_ACTION;
		}
		return self::ROUTE_VALID;
	}
1081212
public function route($param = null, $default = null)
    {
        $route = \call_user_func($this->getRouteResolver());

        if (\is_null($route) || \is_null($param)) {
            return $route;
        }

        return Arr::get($route[2], $param, $default);
    }
829268
public static function getCurrentRouteLink($get_params = []) {
        $current_action = \Illuminate\Support\Facades\Route::current()->getAction();
        $controller = '\\' . $current_action['controller'];
        $parameters = \Illuminate\Support\Facades\Route::current()->parameters();

        return action($controller, $parameters) . ($get_params ? '?' . http_build_query($get_params) : '');
    }
1229156
public function getDynamicLoader($controller, $params = null){
        $attributes = [
            'data-config'     => $this->configUrl,
            'src'             => $this->requireJsUrl,
            'data-main'       => $this->bootstrapUrl,
            'data-controller' => $controller
        ];

        if(!is_null($params)){
            $attributes['data-params'] = json_encode($params);
        }

        return $this->buildScriptTag($attributes);
    }
1171249
static public function encode(?string $module = '', ?string $controller = "", ?string $action = "", ?array $params = []): string
    {
        // 配置中的根
        $url = configDefault('/', 'system', 'host');

        // 配置中的路由模式
        $mode = configDefault('传统模式', 'system', 'url_mode');

        //取默认MCA
        list($defaultM, $defaultC, $defaultA) = self::getMCADefault();

        //如果未提供,则使用默认值
        $module = $module ?: $defaultM;
        $controller = $controller ?: $defaultC;
        $action = $action ?: $defaultA;

        // 根据路由配置进行编码
        $router = configDefault([], 'router');
        foreach ($router as $key => $case) {
            // 这个不是路由配置,而是参数
            if (substr($key, 0, 1) == '_') continue;

            // 如果没有编码这个配置项
            if (!isset($case['encode']) or !$case['encode']) continue;

            //如果编码是一个方法
            if (is_callable($case['encode'])) {
                //调用 回调方法进行转义
                $return = $case['encode']($module, $controller, $action, $params);

                //如果不符合规则,下一条
                if (!$return) continue;

                //处理的结果
                list($pattern, $params) = $return;
                $params = $params ?: [];

                //转义后处理
                return self::encodeMatched($pattern, $params);
            }

            // 取配置,前三项为模块名,控制器,动作名称
            $rule = $case['encode'];
            list ($m, $c, $a) = $rule;

            // 如果控制器与动作相同,使用此规则
            if ($m == $module and $c == $controller and $a == $action) {
                // 把控制器名称和动作名称替换进去
                $pattern = str_replace(['{m}', '{c}', '{a}'], [$module, $controller, $action], $rule[3]);

                //转义后处理
                return self::encodeMatched($pattern, $params);
            }
        }

        // 例 /<m>/<c>/<a>/<k1>/<v1>/<k2>/<v2>/...
        if ($mode == '路径模式') {
            if ($module) $url .= $module . '/';

            // 附加控制器名和动作名
            if ($controller) {
                $url .= $controller . '/';
                if ($action) $url .= $action . '/';
            }

            // 附加参数
            foreach ($params as $key => $value) {
                if (!is_null($value)) $url .= $key . '/' . urlencode($value) . '/';
            }
            return trim($url, '?');
        }

        if ($mode == '传统模式') {
            // 例: /index.php?<k1>=<v1>&<k2=v2>...
            $url .= 'index.php';
        }

        $url .= '?';

        // 取三项参数名
        list ($mName, $cName, $aName) = self::$mcaName;

        // 附加模块名称
        if ($module) $url .= $mName . '=' . $module . '&';

        // 附加控制器名称
        if ($controller) $url .= $cName . '=' . $controller . '&';

        // 附加动作名称
        if ($action) $url .= $aName . '=' . $action . '&';

        // 附加参数
        foreach ($params as $key => $value) {
            $url .= $key . '=' . urlencode('' . $value) . '&';
        }
        return trim(trim($url, '&'), '?');
    }
842851
public function createUrl($controller, array $args = array(), $index = 0)
    {
        $collection = $this->mapManager->findUriTemplatesByController($controller);

        if (!empty($collection)) {
            if (isset($collection[$index])) {
                return $this->createVariadicUrl($collection[$index], $args);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
213990
public function patch(string $module, string $controller): Link
    {
        return $this->addMap(RequestMethod::PATCH, $module, $controller);
    }
752809
private function generateUrlForRoute($route, $params)
    {
        $url = $route['uri'];

        while (count($params) > 0) {
            $param = array_shift($params);
            $url = preg_replace('/{.+?}/', $param, $url, 1);
        }

        return $url;
    }
1213806
static function load($controller, $action = '', $params = array())
	{

		$class_name = ucfirst($controller);
		$method = $action;
		$tc = "Controller\\" . $class_name;
		if (!class_exists($tc)) return self::er("Class $tc does not exist.");
		$this_object = new $tc($params);


		if (!method_exists($this_object, $method)) {
			return self::er("Method $method in $tc does not exist.");
		}


		if (!is_callable(array($this_object, $method))) return self::er("Method $method in $tc is not callable.");
		if (is_callable(array($this_object, "__before"))) {
			call_user_func(array($this_object, "__before"));
		}


		call_user_func(array($this_object, $method));

		if (is_callable(array($this_object, "__after"))) {
			call_user_func(array($this_object, "__after"));
		}
		return $this_object;
	}
358815
public function generateUrl(AdminInterface $admin, $action, $params = [])
    {
        $routeName = $this->getRouteName($admin, $action);

        return $this->router->generate($routeName, $params);
    }
500755
public static function Route($route, $controller, $closure = null) {
        $route = strtolower($route);
        $controller = ucwords(strtolower($controller));
        $request = KernelHttp::request();
        if($request->getUrlApi() == $route)
            self::explorer($route, $controller, $closure, $request);
    }
1138677
private function parseCustomRoute($params, $routesFile, $moduleRoute=FALSE) {
		
		$this->routes = array();
		
		// trigger for route processed
		$routeMatches = FALSE;
			
		// check if controller file exists
		if (!file_exists($routesFile)) {
			return FALSE;
		}
			
		// read the custom routes by php file
		require $routesFile;
		
		// check about the third parameter $module in the custom-routes available as of now
		foreach ($this->routes as $r) {
			
			// force initial slash
			if (!$r->path) {
				$r->path = '/';
			} else if ('/' != $r->path{0}) {
				$r->path = '/' . $r->path;
			}
			
			// add module prefix if not set
			if ($moduleRoute and strpos($r->path,'/'.$this->module) !== 0) {
				$r->path = '/' . $this->module . $r->path;
			}

			// replace any regex after param name in path
			$pathRegex = preg_replace('|/:[^/(]+\(([^)]+)\)|', '/($1)', $r->path);
			
			// then replace simple param name in path
			$pathRegex = preg_replace('|/(:[^/]+)|', '/([^/]+)', $pathRegex);
			
			// compare current URL to regex
			if (preg_match('|^' . $pathRegex . '$|', $this->url)) {
				
				// assign action
				$this->action = $r->action;
				
				// assign even module
				if (!$moduleRoute and !$this->module) {
					if ($r->module) {
						$this->setModule($r->module);
					} else if (isset($params[0])) {
						$this->setModule($params[0]);
					}
				}
				
				// clean-up and split the route path
				$parts = array_values(array_filter(explode('/', $r->path)));
				
				// initialize array of temporary variables
				$variables = array();
				
				// store the variables found with name and position
				foreach ($parts as $pos => $part) {
					
					// search for the colon symbol that precedes the variable name
					if (substr($part,0,1) == ':') {
						
						// search for a possible regular expression
						$regexPos = strpos($part, '(');
						
						// remove the colon and any regex after variable name
						$variables[$pos] = FALSE === $regexPos ?
							substr($part,1) :
							substr($part,1,$regexPos-1);
						
					}
					
				}
				
				// assign params to vars array and set page, order and log
				foreach ($params as $pos => $value) {
					
					// flag to not send back log (useful for AJAX)
					if ('noLog' == $value) {
						
						$this->sendLog = FALSE;
						
					// ordering
					} else if ('order-' == substr($value, 0, 6)) {
						
						$nr = intval(substr($value, 6));
						if ($nr) $this->order = $nr;

					// pagination
					} else if ('page-' == substr($value, 0, 5)) {
						
						$nr = intval(substr($value, 5));
						$this->setPage($nr);
						
					// create a var with parsed name
					} else if (isset($variables[$pos]) and $variables[$pos]) {
						
						$this->vars[$variables[$pos]] = $value;
						
					// otherwise assign the param by its index position
					} else {
						
						$this->vars[$pos] = $value;
						
					}
								
				}
				
				$routeMatches = TRUE;
				
				break;
				
			}
			
		}
		
		return $routeMatches;
		
	}