Build URL by custom route

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

@return string
322960
protected function urlCustom($module, $controller, $params): string
    {
        $url = $this->reverse[$module][$controller]['route'];

        $getParams = [];
        foreach ($params as $key => $value) {
            // sub-array as GET params
            if (\is_array($value)) {
                $getParams[$key] = $value;
                continue;
            }
            $url = str_replace('{$' . $key . '}', $value, $url, $replaced);
            // if not replaced, setup param as GET
            if (!$replaced) {
                $getParams[$key] = $value;
            }
        }
        // clean optional params
        $url = preg_replace('/\{\$[a-z0-9-_]+\}/i', '', $url);
        // clean regular expression (.*)
        $url = preg_replace('/\(\.\*\)/', '', $url);
        // replace "//" with "/"
        $url = str_replace('//', '/', $url);

        if (!empty($getParams)) {
            $url .= '?' . http_build_query($getParams);
        }
        return $this->getBaseUrl() . ltrim($url, '/');
    }
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;
    }
53158
public function getUrl($params): string
    {
        // prepare params
        $params = $this->getParams($params);

        // retrieve URL
        return Router::getUrl(
            $this->getModule(),
            $this->getController(),
            $params
        );
    }
1067109
private function dispatchMvc($module, $controller, $action, $params)
    {
        return Dispatcher::mvcDispatcher($module, $controller, $action, $params);
    }
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;
    }
1225839
public static function param($param,$moduleName=''){
		if($moduleName){
			//echo $moduleName;exit;
			return Yii::$app->getModule($moduleName)->params[$param];
		}else{
			return Yii::$app->controller->module->params[$param];
		
		}
	}
828907
public function build($params = [], $anchor = '')
    {
        if (!count($params)) {
            return '/';
        }

        $config = Application::getConfigManager()->loadForModule('Cmf\System', 'module');

        $defaultModule = mb_strtolower($config->defaultModule);
        $defaultController = mb_strtolower($config->defaultController);
        $defaultAction = mb_strtolower($config->defaultAction);

        $defaults = ['module' => $defaultModule, 'controller' => $defaultController, 'action' => $defaultAction,];
        $params = array_merge($defaults, $params);

        $module = preg_replace('/^(Cmf\\\\)/', '', $params['module']);
        $module = str_replace('\\', '-', $module);
        $module = ltrim(mb_strtolower(preg_replace('/([A-Z])/', "_$1", $module)), '_');
        $module = str_replace('-_', '-', $module);

        $controller = ltrim(mb_strtolower(preg_replace('/([A-Z])/', "_$1", $params['controller'])), '_');
        $action = mb_strtolower($params['action']);

        $fullModuleName = mb_strtolower($params['module']);
        if ($fullModuleName == $defaultModule && $controller == $defaultController && $action == $defaultAction) {
            $url = '';
        } elseif ($controller == $defaultController && $action == $defaultAction) {
            $url = '/' . urlencode($module) . '/';
        } elseif ($action == $defaultAction) {
            $url = '/' . urlencode($module) . '/' . urlencode($controller);
        } else {
            $url = '/' . urlencode($module) . '/' . urlencode($controller) . '/' . urlencode($action);
        }

        foreach ($params as $key => $val) {
            if (in_array($key, array('module', 'controller', 'action'))) {
                continue;
            } elseif ($val instanceof Sort) {
                /** @var $sort Sort */
                $sort = $val;
                if ($field = $sort->getField()) {
                    $sortName = $sort->getRequestVariable();
                    $url .= '/' . $sortName . '~field~' . $field;
                    if ($direction = $sort->getDirection()) {
                        $url .= '/' . $sortName . '~direction~' . $direction;
                    }
                }
            } elseif ($val) {
                if ($part = $this->buildRecursive(urlencode($key), $val)) {
                    $url .= ($url ? '/' : '') . $part;
                }
            }
        }

        if (!$url) {
            $url = '/';
        }

        if ($anchor) {
            $url .= '#' . urlencode($anchor);
        }

        return $url;
    }
843951
public function runController($controller, $method, Array $params) {
    $transactional = $controller instanceof \Psc\CMS\Controller\TransactionalController;
    
    try {
      try {
        $this->logf('running Controller: %s::%s(%s)', Code::getClass($controller), $method, implode(', ',array_map(function ($param) { return Code::varInfo($param); }, $params)));
        $cb = new Callback($controller, $method);
        $controllerResponse = $cb->call($params);
        
        $this->log('Converting Controller Response');
        $this->setResponseFromControllerResponse($controllerResponse);
        $this->log('Response Format: '.($this->response->getFormat() ?: 'null'));
        $this->log('successful run');
        
        $this->log('überprüfe ResponseMetadataController');
        if ($controller instanceof \Psc\CMS\Controller\ResponseMetadataController && ($meta = $controller->getResponseMetadata()) != NULL) {
          $this->response->setMetadata($meta);
          $this->log('Metadaten übertragen');
        }
        
      /* PDO Exceptions */
      } catch (\PDOException  $e) {
        throw \Psc\Doctrine\Exception::convertPDOException($e);
      }

    } catch (\Exception $e) {
      if ($transactional && $controller->hasActiveTransaction())
        $controller->rollbackTransaction();
      
      $this->handleException($e);
    }
  }
807112
protected function makeController($name, $module, $is_module = false) {
        return ModuleGenerator::renderTemplate('Controller', [
            'module' => $module,
            'name' => $name,
            'is_module' => $is_module
        ]);
    }
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);
    }
661272
public static function build($controller)
    {
        $routes = array();
        $actions = self::parseActionMethods($controller);

        foreach ($actions as $actionName => $actionInfo) {
            list($annotations, $meta) = $actionInfo;

            if (isset($annotations['Route'])) {
                $path = $annotations['Route'];
            } else {
                if ($actionName === 'indexAction') {
                    $path = '';
                } else {
                    $path = self::translatePath($actionName); // '/' . preg_replace_callback('/[A-Z]/', function($matches) {
                }
            }

            $route = array($path, $actionName);

            if (isset($annotations['Method'])) {
                $route[] = array('method' => Mux::convertRequestMethodConstant($annotations['Method']));
            } else {
                $route[] = array();
            }
            $routes[] = $route;
        }

        return $routes;
    }
635183
public function getLink($controller, $params = array(), $fullPath = false)
    {
        if ($controller instanceof Controller) {
            $controller = get_class($controller);
        }
        $controller = (string)$controller;
        if(substr($controller, 0, 1) === "\\") {
            $controller = substr($controller, 1);
        }
        try {

            $url = Bootstrap::getSingleton()->getManager()->getRouter()->generate($controller, $params);
            if ($fullPath) {
                $protocol = 'http';
                if (strpos($_SERVER['SCRIPT_URI'], 'https') !== false) {
                    $protocol = 'https';
                }
                return $protocol . '://' . $_SERVER['HTTP_HOST'] . $url;
            }
            return $url;
        } catch (\Exception $ex) {

        }
        return "";
    }
1075678
public static function registerRoute($controller, $parameters = [])
    {
        \Route::group($parameters, function ($controller) {
            \Route::registerController($controller);
        });
    }
1019039
public function widget($module, $controller = 'index', $action = 'index', array $params = [])
    {
        return \Mmi\Mvc\ActionHelper::getInstance()->action((new \Mmi\Http\Request($params))
                ->setModuleName($module)
                ->setControllerName($controller)
                ->setActionName($action));
    }
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;
		
	}
1314048
public function make($module, $action = "", $id = null, $params = []) {
        $url = URL_ABSOLUTE . $module;
        if ($action !== "") {
            $url .= '-' . $action;
            if ($id !== null) {
                $url .= '-' . $id;
            }
        }

        $first = true;
        foreach ($params as $i => $param)
        {
            if ($first) {$url .= "?"; $first=false;}
            else {$url .= "&";}
            $url .= $i . "=" . $param;
        }
        return $url;
    }
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);
		}