Creates URL

@param string $controller
@param array $args
@param integer $index
@return string
347279
final protected function createUrl($controller, array $args = array(), $index = 0)
    {
        if (ArrayUtils::isAssoc($args)) {
            return $this->urlBuilder->createQueryUrl($controller, $args, $index);
        } else {
            return $this->urlBuilder->createUrl($controller, $args, $index);
        }
    }
649690
public function triggerController(string $controller, ...$args)
    {
        //extract the class and method
        list($class, $method) = explode('@', $controller, 2);

        //if the class exists
        if (class_exists($class)) {
            //instantiate it
            $instance = new $class();

            //does the method exist ?
            if (method_exists($instance, $method)) {
                call_user_func_array([$instance, $method], $args);
            }
        }

        return $this;
    }
516593
private static function execController($controller,$action,$args){
        $controller = new $controller();
        $controller->doAction($action,$args);
    }
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);
    }
201026
public static function createRouteFile(string $slug, $controller = 'PostController')
    {
        $stub =  File::get(stubPath('PostType'));
        $route = str_replace('DummySlug', cleanPostTypeSlug($slug), $stub);
        $route = str_replace('DummyController', $controller, $route);
        $bytes_written = File::put(base_path().'/routes/'.$slug.'.php', $route);
        if ($bytes_written === false) {
            die("Error writing to new route file");
        }
        return $route;
    }
935512
private function exec( $controller_name, $args )
	{
		// Process controller
		$compo = explode( '@', $controller_name );

		if ( count( $compo ) <= 1 ) {

			throw new Exception( sprintf( 'Controller action must be defined in %s.', $controller_name ) );

		}

		// Get controller
		require_once(  $this->controllers_path . $compo[0] . '.php' );
		$classname = sprintf( $this->namespace . '\Controllers\%s', $compo[0]);
		$controller = new $classname( $this->view );

		if ( !method_exists( $controller, $compo[1] ) ) {

			throw new Exception( sprintf( 'Controller action "%s" not found in %s.', $compo[1], $compo[0] ) );

		}

		return call_user_func_array( [ $controller, $compo[1] ], $args );
	}
510992
public function href(string $controller = null, string $action = null, array $params = null, string $lang = null): string
    {
        return $this->siteHref('', $controller, $action, $params, $lang);
    }
99689
public function controller($route, ...$args) {
		// Sanitize the call
		$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);

		// Keep the original trigger
		$trigger = $route;

		// Trigger the pre events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/before', array(&$route, &$args));

		// Make sure its only the last event that returns an output if required.
		if ($result != null && !$result instanceof Exception) {
			$output = $result;
		} else {
			$action = new Action($route);
			$output = $action->execute($this->registry, $args);
		}

		// Trigger the post events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/after', array(&$route, &$args, &$output));

		if ($result && !$result instanceof Exception) {
			$output = $result;
		}

		if (!$output instanceof Exception) {
			return $output;
		}
	}
743601
final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) {
        return $this->view->url($module, $controller, $action, $params, $hash);
    }
1166981
public function setUrl($pageName, $controller)
    {
        $params = [
            'id'   => $this->id,
            'slug' => $this->slug
        ];

        $params['category'] = $this->categories->count() ? $this->categories->first()->slug : null;

        // Expose published year, month and day as URL parameters.
        if ($this->published) {
            $params['year']  = $this->published_at->format('Y');
            $params['month'] = $this->published_at->format('m');
            $params['day']   = $this->published_at->format('d');
        }

        return $this->url = $controller->pageUrl($pageName, $params);
    }
369187
public static function href($controller = null, string $action = null, array $params = null): string
    {
        return Application::route()->href($controller, $action, $params);
    }
492279
private function getRawAndModuleControllers($controller, $module) {
        if ('/' == $module || '' == $module) {
            $rController = $controller;
            $allController = '*';
        } elseif (null === $module) {
            $rController = \mpf\WebApp::get()->request()->getModule() . '/' . $controller;
            $allController = \mpf\WebApp::get()->request()->getModule() . '/*';
        } else {
            $rController = $module . '/' . $controller;
            $allController = $module . '/*';
        }
        return array($rController, $allController);
    }
325883
public final function index(...$args) {
        $len = count($args);
        switch ($len) {
            case 0:
                return null;
            case 1:
                $subname = array_shift($args);
                $action  = 'index';
                break;
            default:
                $subname = array_shift($args);
                $fParam  = $action = array_shift($args);
        }
        if (empty($subname) || empty($action)) {
            return null;
        }
        $module = $this->module->getDirname();
        $app    = DefaultDispatcher::findApp($module, $action, $args, $this->module->getNamespace(), $subname);
        if ($app) {
            list ($controllerClz, $action, $pms, , $controllerSlag, $actionSlag) = $app;
            if (in_array($action, ['beforerun', 'afterrun', 'geturlprefix'])) {
                return null;
            }
            try {
                $clz = new $controllerClz ($this->module);

                if ($clz instanceof Controller && $clz->slag == $controllerSlag) {
                    $rqMethod = strtolower($_SERVER ['REQUEST_METHOD']);
                    $rm       = ucfirst($rqMethod);
                    // 存在index_get,index_post,add_get add_post这新的方法.
                    $md          = $action . $rm;
                    $actionFound = false;
                    if (method_exists($clz, $md)) {
                        $action      = $md;
                        $actionSlag  = $actionSlag . '-' . $rqMethod;
                        $actionFound = true;
                    } else if (!method_exists($clz, $action)) {
                        array_unshift($pms, $actionSlag);
                        $action     = 'index';
                        $actionSlag = 'index';
                    }
                    if (!$actionFound) {
                        $md = $action . $rm;
                        if (method_exists($clz, $md)) {
                            $action      = $md;
                            $actionSlag  = $actionSlag . '-' . $rqMethod;
                            $actionFound = true;
                        } else if (method_exists($clz, $action)) {
                            $actionFound = true;
                        }
                    }
                    if ($actionFound) {
                        $ref        = $clz->reflectionObj;
                        $method     = $ref->getMethod($action);
                        $methodSlag = Router::addSlash($method->getName());
                        if (!$method->isPublic() || $methodSlag != $actionSlag) {
                            return null;
                        }
                        /* @var \ReflectionParameter[] $params */
                        $params      = $method->getParameters();
                        $paramsCount = count($params);
                        if ($paramsCount < count($pms)) {
                            return null;
                        }
                        $rtn = $clz->beforeRun($action, $method);

                        $module .= '/' . $subname;
                        //beforeRun可以返回view了
                        if ($rtn instanceof View) {
                            DefaultDispatcher::prepareView($rtn, $module, $clz, $action);

                            return $rtn;
                        }
                        $args = [];

                        if ($paramsCount) {
                            $idx = 0;
                            foreach ($params as $p) {
                                $name    = $p->getName();
                                $def     = isset ($pms [ $idx ]) ? $pms [ $idx ] : ($p->isDefaultValueAvailable() ? $p->getDefaultValue() : null);
                                $value   = rqst($name, $def, true);
                                $args [] = is_array($value) ? array_map(function ($v) {
                                    return is_array($v) ? $v : urldecode($v);
                                }, $value) : urldecode($value);
                                $idx++;
                            }
                        }
                        $view = $clz->{$action}(...$args);
                        if ($view !== null) {
                            if (is_array($view)) {
                                $view = new JsonView($view);
                            } else if (!$view instanceof View) {
                                $view = new SimpleView($view);
                            } else {
                                DefaultDispatcher::prepareView($view, $module, $clz, $action);
                            }
                        }

                        return $clz->afterRun($action, $view, $method);
                    }
                }
            } catch (\Exception $e) {
                if (DEBUG == DEBUG_DEBUG) {
                    throw $e;
                }
            }
        }

        //通过插件扩展路由
        $ns = 'router:' . $this->module->getNamespace() . '/' . $subname;
        if (isset($fParam)) {
            array_unshift($args, $fParam);
        }

        return apply_filter($ns, null, $args);
    }
876829
public function addMap($method, $module, $controller): Link
    {
        return $this->map[strtoupper($method)] = new Link($module, $controller);
    }
560181
public function resource($uri, $controller, array $options = [])
    {
        $this->get($uri, "$controller@index", $options);
        $this->post($uri, "$controller@store", $options);
        $this->get("$uri/{placeholder}", "$controller@show", $options);
        $this->put("$uri/{placeholder}", "$controller@update", $options);
        $this->delete("$uri/{placeholder}", "$controller@delete", $options);
    }
1369435
protected function createController($controller)
    {
        if (false === strpos($controller, '::')) {
            throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller));
        }

        list($class, $method) = explode('::', $controller, 2);

        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
        }

        return array(new $class(), $method);
    }
1251207
public static function resource($url, $controller)
    {
        $route = new self($url);

        $route->targets = ['index', 'show', 'insert', 'add', 'update', 'edit', 'delete'];

        $route->setResourceMethods($url, $controller);

        return $route;
    }