Build URL to controller

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

@return string
979651
public function getUrl(
        $module = self::DEFAULT_MODULE,
        $controller = self::DEFAULT_CONTROLLER,
        array $params = []
    ): string {
        $module = $module ?? Request::getModule();
        $controller = $controller ?? Request::getController();

        if (isset($this->reverse[$module], $this->reverse[$module][$controller])) {
            return $this->urlCustom($module, $controller, $params);
        }

        return $this->urlRoute($module, $controller, $params);
    }
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;
    }
1098381
public function redirect($module, $controller = null, $action = null, array $params = [], $reset = true)
    {
        //jeśli włączone resetowanie parametrów
        if (!$reset) {
            //parametry z requestu front controllera
            $requestParams = \Mmi\App\FrontController::getInstance()->getRequest()->toArray();
            //łączenie z parametrami z metody
            $params = array_merge($requestParams, $params);
        }
        //jeśli istnieje akcja
        if ($action !== null) {
            $params['action'] = $action;
        }
        //jeśli istnieje kontroler
        if ($controller !== null) {
            $params['controller'] = $controller;
        }
        //ustawienie modułu
        $params['module'] = $module;
        //przekierowanie na routę
        $this->redirectToRoute($params);
    }
1147043
public function delete(string $module, string $controller): Link
    {
        return $this->addMap(RequestMethod::DELETE, $module, $controller);
    }
372819
final public function getOutput($module, $controller, $action, array $params = array(), $partial = true) {
        $view = new View();
        $controllerClass = ucfirst(\Util::hyphenToCamel($module)) . '\Controllers\\' . ucfirst(\Util::hyphenToCamel($controller)) . 'Controller';
        $controllerClass = new $controllerClass;
        $controllerClass->setView($view);
        $action = lcfirst(\Util::hyphenToCamel($action));
        $view->setController($controllerClass)
                ->setAction(lcfirst(\Util::hyphenToCamel($action)))
                ->setModule(ucfirst(\Util::hyphenToCamel($module)));
        $actionRet = call_user_func_array(array($controllerClass, $action . 'Action'), $params);
        if (is_object($actionRet) && is_a($actionRet, 'DScribe\View\View')) {
            $view = $actionRet;
        }
        else {
            $view->variables(($actionRet) ? $actionRet : array());
        }
        if ($viewFile = $view->getViewFile(false)) {
            if (!isset($viewFile[0]) && !isset($viewFile[1])) {
                $view->file($module, $controller, $viewFile[2]);
            }
            else if (!isset($viewFile[0])) {
                $view->file($module, $viewFile[1], $viewFile[2]);
            }
        }
        else {
            $view->file($module, $controller, $action);
        }

        if ($partial) {
            $view->partial();
        }

        ob_start();
        $view->render();
        return ob_get_clean();
    }
422493
public static function redirectTo($module, $controller = 'index', array $params = []): void
    {
        $url = Router::getFullUrl($module, $controller, $params);
        self::redirect($url);
    }
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];
		
		}
	}
431679
public function options(string $module, string $controller): Link
    {
        return $this->addMap(RequestMethod::OPTIONS, $module, $controller);
    }
199916
protected function forward(string $controller, array $action = [], array $params = [])
    {
        return $this->dispatcher->forward([
            'handler' => $controller,
            'action' => $action,
            'params' => $params,
        ]);
    }
504487
protected function makeController($controller)
    {
        Controller::setRouter($this->router);

        $controller = $this->container->make($controller);

        if ( ! $controller instanceof AdminPageController)
        {
            if ($this->container->isShared('post'))
            {
                $controller->setPost($this->container['post']);
            }

            $controller->setQuery($this->container['query']);
        }

        if (method_exists($controller, 'boot'))
        {
            $this->container->call([$controller, 'boot']);
        }

        return $controller;
    }
1319827
protected function invoke($controller, $method, $params)
    {
        if (!class_exists($controller)) {
            throw new Exception("Controller [ $controller ] does not exist.");
        }

        try {
            $instance = $this->container->make($controller);

            $resolving = $this->container->resolveMethod($controller, $method, $params, true);

            $this->validateForm($resolving);

            return call_user_func_array([$instance, $method], $resolving);
        } catch (DefinitionException $e) {
            throw new BindingException("Binding Error [ ". $e->getMessage() ." ]");
        }

    }
172552
static function ModuleUrl(BackendModule $module, array $args = array())
    {
        $allArgs = array('module'=> ClassFinder::ModuleType($module)) + $args;
        return 'index.php?' . http_build_query($allArgs);
    }
497950
public static function isModule(string $module, string $controller = null, string $action = null): bool
    {
        $route = Application::route();
        if ($module === $route->getModuleUrl()) {
            if ($controller === null) {
                return true;
            } else {
                if ($controller === $route->getControllerUrl()) {
                    // now we have matched module and controller
                    if ($action === null) {
                        return true;
                    } else {
                        return ($action === $route->getActionUrl());
                    }
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
441604
public function getController($module, $handler=null, $type='Controller')
	{
	    $module    = isset($module) ? trim($module, '/') : '';
	    $handler   = isset($handler) ? trim($handler, '/') : '';
	    
	    // has module and contain '/': 'demo/demo2'
	    if ($module && strpos($module, '/')) {
	        if ($handler === 'index') {
	            $handler = '';
	        }
	        
            // think about performance, module limit / level.
            $moduleLevel = intval(Config::get('router.module_level')) ? : 1;
            if ($moduleLevel < 0) {
                $moduleLevel = 1;
            } elseif ($moduleLevel > 2) {
                $moduleLevel  = 2;
            }
            
            $parts = explode('/', $module, $moduleLevel + 1);
            
            if (count($parts) <= $moduleLevel) {
                if ($module && $moduleInstance = $this->getModule($module)) {
                    return $moduleInstance->getController(null, $handler, $type);
                }
            }
            
            $mhandler = array_pop($parts);
            $module   = implode('/', $parts);
            
            if ($mhandler === 'index') {
                $mhandler = '';
            }
            $handler = $handler ? $mhandler . '/' . $handler : $mhandler;
            
	        if ($module && $moduleInstance = $this->getModule($module)) {
	            Ioc::logger('router')->debug(sprintf('[find][m][%s]%s:%s', UriHelper::getRelativeUrl(), $module, $handler));
	            return $moduleInstance->getController(null, $handler, $type);
	        } else {
	            return static::getController($module, $handler, $type);
	        }
	    }
	    // has module and not contain '/': 'demo'
	    elseif ($module && $moduleInstance = $this->getModule($module)) {
	        Ioc::logger('router')->debug(sprintf('[find][m][%s]%s:%s', UriHelper::getRelativeUrl(), $module, $handler));
	        
	        return $moduleInstance->getController(null, $handler, $type);
	    }
	    // as controller 'a/b'+'c'
	    else {
            // 如， /a/b 1) 先查找对应控制器 a/b， 2)不存在则查找 a/b/index， 3) 不存在当包含/时则查找 a并把b当作action，不含/时则找 index并把控制器名当作action
            $namespace  = $this->getNamespace();
            $handler = implode('/', [$module, $handler]);
			$handler = trim($handler, '/') ? : 'index'; 
			$className  = Ioc::findClass($handler, $type, $namespace); 
			$action = null; 
			
			Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
			
			if (!$className) {
			    if ($handler == 'index') {
			        return null;
			    }
			    
			    $indexClassName = Ioc::findClass($handler . '/index', $type, $namespace);
			    
			    Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler . '/index'));
			    
			    if ($indexClassName) {
					$handler    = $handler . '/index';
					$className  = $indexClassName;
				} else {
				    if (($pos = strrpos($handler, '/')) !== false) {
				        $action = substr($handler, $pos + 1);
				        $handler = substr($handler, 0, $pos); 
				        $className  = Ioc::findClass($handler, $type, $namespace);
				        
				        Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				        
				        if (!$className) {
				            $handler .= '/index';
				            $className = Ioc::findClass($handler, $type, $namespace);
				            
				            Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				            
				            if (!$className) {
				                return null;
				            }
				        }
				    } else {
				        $action  = $handler;
				        $handler = 'index';
				        $className  = Ioc::findClass($handler, $type, $namespace);
				        
				        Ioc::logger('router')->debug(sprintf('[find][c][%s]%s:%s', UriHelper::getRelativeUrl(), $this->getName(), $handler));
				        
				        if (!$className) {
				            return null;
				        }
				    }
				}
			}
			
			/** @var $object ControllerInterface */
			$object = new $className($handler);
			
			if (!$object instanceof ControllerInterface) {
			    if (Ioc::app() && Ioc::app()->isCli() && class_exists('\\Wslim\\Console\\Controller')) {
			        $object = new \Wslim\Console\Controller($object);
			    } elseif (Ioc::app() && !Ioc::app()->isCli() && class_exists('\\Wslim\\Web\\Controller')) {
			        $object = new \Wslim\Web\Controller($object);
			    } else {
                    $object = new Controller($object);
			    }
			}
			$object->setModule($this);
			$object->setAction($action);
			
			return $object;
		}
	}
265902
public static function buildURL($controller, array $params = [], string $host = '') : string {
		if (empty($host)) {
			$host = \Request::host();
		}
		$controller = ltrim($controller, '/');
		return $host . $controller . '?' . http_build_query2($params);
	}
735309
public function url()
    {
        $args = func_get_args();
        $controller = array_shift($args);

        $url = $this->urlBuilder->createUrl($controller, $args);

        if ($url === false) {
            return $controller;
        } else {
            return $url;
        }
    }
193330
private function _load_controller($uri = '', $params = [], $return = false)
    {
        $router = &$this->_ci_get_component('router');

        // Back up current router values (before loading new controller)
        $backup = [];
        foreach (['directory', 'class', 'method', 'module'] as $prop) {
            if ($prop == 'module') {
                $prop = $this->module->getCurrent();
            }
            $backup[$prop] = $router->{$prop};
        }

        // Locate the controller
        $segments = $router->locate(explode('/', $uri));
        $class    = isset($segments[0]) ? $segments[0] : false;
        $method   = isset($segments[1]) ? $segments[1] : "index";

        // Controller not found
        if (!$class) {
            return;
        }

        if (!array_key_exists(strtolower($class), $this->_ci_controllers)) {
            // Determine filepath
            $filepath = APPPATH . 'controllers/' . $router->fetch_directory() . $class . '.php';
            // Load the controller file
            if (file_exists($filepath)) {
                include_once $filepath;
            }
            // Controller class not found, show 404
            if (!class_exists($class)) {
                show_404("{$class}/{$method}");
            }
            // Create a controller object
            $this->_ci_controllers[strtolower($class)] = new $class();
        }

        $controller = $this->_ci_controllers[strtolower($class)];

        // Method does not exists
        if (!method_exists($controller, $method)) {
            show_404("{$class}/{$method}");
        }

        // Restore router state
        foreach ($backup as $prop => $value) {
            $router->{$prop} = $value;
        }

        // Capture output and return
        ob_start();
        $result = call_user_func_array([$controller, $method], $params);

        // Return the buffered output
        if ($return === true) {
            $buffer = ob_get_contents();
            @ob_end_clean();
            return $buffer;
        }

        // Close buffer and flush output to screen
        ob_end_flush();

        // Return controller return value
        return $result;
    }