通过路由获取短网址
@param string $route slug
@param array $params URL参数
@return mixed|null|static
19780
public function getSlug($route, $params = [])
    {
        $dbRoute = Yii::$app->cache->get([$route, $params]);
        if (YII_ENV_DEV || $dbRoute == false) {
            $dbRoute = UrlRule::getRoute($route, $params);
            Yii::$app->cache->set(
                [$route, $params],
                $dbRoute
            );
        }
        return $dbRoute;
    }
895796
public function setRoute($route, array $params = array())
    {
        $this->route = $route;
        $this->routeParams = $params;

        return $this;
    }
884441
public function parse($route)
    {
        // reset param names
        $this->paramNames = [];

        // replace shortcuts
        $regex = strtr($route, $this->shortcuts);

        // replace param names that doesn't include shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+)}/', [$this, 'replaceWithoutRegex'], $regex);

        // replace param names that includes shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+):/', [$this, 'replaceWithRegex'], $regex);

        // replace ending grouping
        $regex = str_replace('}', ')', $regex);

        // fix slashes when optional params are present
        $regex = $this->fixOptionalSlashes($regex);

        // fix for handling trailing slashes
        $regex .= '(/)?';

        // return regex and param names
        return ['#^'. $regex .'$#', $this->paramNames];
    }
63115
public function createPathInfo(UrlManager $urlManager, $route, $params, $ampersand)
    {
        $tr = [];
        if ($route !== $this->route) {
            if (null !== $this->routePattern && preg_match($this->routePattern, $route, $m)) {
                foreach ($this->references as $key => $name) {
                    $tr[$name] = $m[$key];
                }
            } else {
                return false;
            }
        }
        // 默认参数
        foreach ($this->defaultParams as $key => $value) {
            if (isset($params[$key])) { // 一旦设置必须和配置的一致
                if ($params[$key] == $value) {
                    unset($params[$key]);
                } else {
                    return false;
                }
            }
        }
        // 规定参数必须设置，否则不匹配该规则
        foreach ($this->params as $key => $value) {
            if (!isset($this->params[$key])) {
                return false;
            }
            $tr["<$key>"] = urlencode($params[$key]);
            unset($params[$key]);
        }
        $url = strtr($this->template, $tr);
        if (empty($params)) {
            return $url !== '' ? $url . $urlManager->urlSuffix : $url;
        }
        // 还有未在pattern中出现的参数
        if ($this->append) {
            // 允许pathInfo 追加
            $url .= '/' . $urlManager->createPathInfo($params, '/', '/') . $urlManager->urlSuffix;
        } else {
            // 不允许追加时，参数放在 "?" 后面
            if ($url !== '') {
                $url .= $urlManager->urlSuffix;
            }
            $url .= '?' . $urlManager->createPathInfo($params, '=', $ampersand);
        }
        return $url;
    }
100141
public function contentForInternalRoute($route = null)
    {
        // Get the route
        if (is_null($route)) {
            $route = $this->di->get("request")->getRoute();
        }

        // Check cache for content or create cached version of content
        $slug = $this->di->get("url")->slugify($route);
        $key = $this->di->cache->createKey(__CLASS__, "route-$slug");
        $content = $this->di->cache->get($key);

        if (!$content || $this->ignoreCache) {
            $content = $this->createContentForInternalRoute($route);
            $this->di->cache->put($key, $content);
        }

        return $content;
    }
761753
public function delete($route, $params = [])
    {
        $route = $this->parseRoute($route, $params);
        $request = Request::create($route, 'DELETE', Input::all());
        $response = Route::dispatch($request);

        return $response;
    }
704064
protected function parse($pattern, $route, $params)
    {
        $pattern = ltrim($pattern, '/');
        if (preg_match_all(self::REGEX, $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
            $regex = '~^';
            $variables = [];
            $offset = 0;
            $i = 1;
            foreach ($matches as $match) {
                if ($match[0][1] > $offset) {
                    $regex .= preg_quote(substr($pattern, $offset, $match[0][1] - $offset), '~');
                }
                $variables['d' . $i] = $match[1][0];
                $_regex = isset($match[2][0]) ? $match[2][0] : self::DEFAULT_REGEX;
                $regex .= "(?P<d{$i}>$_regex)";
                $offset = $match[0][1] + strlen($match[0][0]);
                $i++;
            }

            if ($offset != strlen($pattern)) {
                $regex .= preg_quote(substr($pattern, $offset), '~');
            }
            $regex .= '$~';
            $this->_routes['var'][$regex] = [$route, $params, $variables];
        } else {
            $this->_routes['static'][$pattern] = [$route, $params];
        }
    }
459989
protected function _parse($route) {
		if (is_string($route)) {
			$this->_ensureHere();

			$url = parse_url($route);
			$_path = rtrim($url['path'], '/');
			if ($_path . '?' . Hash::get($url, 'query') === $this->_hereQuery) {
				return true;
			}

			if ($_path === $this->_here) {
				return true;
			}

			return false;
		}

		$count = count($route);
		if ($count == 0) {
			return false;
		}

		foreach ($route as $key => $value) {
			if (array_key_exists($key, $this->request->params)) {
				$values = (array)$value;
				$check = (array)$this->request->params[$key];

				$hasNullValues = (count($values) != count(array_filter($values)) || count($values) == 0);
				$currentValueIsNullish = (in_array(null, $check) || in_array('', $check) || count($check) == 0);
				if ($hasNullValues && $currentValueIsNullish) {
					$count--;
					continue;
				}

				if (in_array($key, array('controller', 'plugin'))) {
					foreach ($check as $k => $_check) {
						$check[$k] = Inflector::underscore(strtolower($_check));
					}
				} else {
					foreach ($check as $k => $_check) {
						$check[$k] = strtolower($_check);
					}
				}

				if (count($values) > 0) {
					foreach ($values as $k => $v) {
						if (in_array(strtolower($v), $check)) {
							$count--;
							break;
						}
					}
				} elseif (count($check) === 0) {
					$count--;
				}
			} elseif (is_numeric($key) && isset($this->request->params['pass'])) {
				if (is_array($this->request->params['pass'])) {
					if (Hash::contains($this->request->params['pass'], $value)) {
						$count--;
					}
				}
			}
		}

		return ($count == 0);
	}
632639
private function getParams($currentPath, $route)
    {
        $path = substr($currentPath, strlen($route));
        $path = (substr($path, 0, 1) == "/") ? substr($path, 1) : $path;
        $path = (substr($path, -1) == "/") ? substr($path, 0, -1) : $path;

        $this->getFilterParams($path);
        $this->getDataParams();
        $this->parseParameterValues();
        $this->cleanReservedParams();
    }
915318
public function uriFor($route, array $params = [], array $query = [])
    {
        if (!$route) {
            return '';
        }

        return $this->router->relativePathFor($route, $params, $query);
    }
1307096
public static function getRoute($slug, $params = [], $status = self::STATUS_ACTIVE)
    {
        return UrlRule::findOne(['slug' => $slug, 'params' => http_build_query($params), 'status' => $status]);
    }
1103953
public static function route($route, $model = null)
    {
        if (!starts_with($route, config('forum.routing.as'))) {
            $route = config('forum.routing.as') . $route;
        }

        $params = [];
        $append = '';

        if ($model) {
            switch (true) {
                case $model instanceof Category:
                    $params = [
                        'category'      => $model->id,
                        'category_slug' => static::slugify($model->title)
                    ];
                    break;
                case $model instanceof Thread:
                    $params = [
                        'category'      => $model->category->id,
                        'category_slug' => static::slugify($model->category->title),
                        'thread'        => $model->id,
                        'thread_slug'   => static::slugify($model->title)
                    ];
                    break;
                case $model instanceof Post:
                    $params = [
                        'category'      => $model->thread->category->id,
                        'category_slug' => static::slugify($model->thread->category->title),
                        'thread'        => $model->thread->id,
                        'thread_slug'   => static::slugify($model->thread->title)
                    ];

                    if ($route == config('forum.routing.as') . 'thread.show') {
                        // The requested route is for a thread; we need to specify the page number and append a hash for
                        // the post
                        $params['page'] = ceil($model->sequence / $model->getPerPage());
                        $append = "#post-{$model->sequence}";
                    } else {
                        // Other post routes require the post parameter
                        $params['post'] = $model->id;
                    }
                    break;
            }
        }

        return route($route, $params) . $append;
    }
516781
public function dispatch(\Parable\Routing\Route $route)
    {
        $this->dispatchedRoute = $route;

        $this->hook->trigger(self::HOOK_DISPATCH_BEFORE, $route);
        $controller = null;

        // Start output buffering and set $returnContent to null
        $returnContent = null;
        $this->response->startOutputBuffer();

        // Build the parameters array
        $parameters = [];
        foreach ($route->getValues() as $value) {
            $parameters[] = $value;
        }

        // Call the relevant code
        if ($route->hasControllerAndAction()) {
            $controller = \Parable\DI\Container::get($route->getController());
            $returnContent = $controller->{$route->getAction()}(...$parameters);
        } elseif ($route->hasCallable()) {
            $callable = $route->getCallable();
            $returnContent = $callable(...$parameters);
        }

        $this->hook->trigger(self::HOOK_DISPATCH_TEMPLATE_BEFORE, $route);

        // If the route has no template path, attempt to build one based on controller/action.phtml
        if (!$route->hasTemplatePath() && $route->hasControllerAndAction()) {
            $reflection = new \ReflectionClass($controller);
            $controllerName = str_replace('\\', '/', $reflection->getName());
            $controllerName = str_replace('Controller/', '', $controllerName);

            $templatePathGenerated = $this->path->getDir(
                "app/View/{$controllerName}/{$route->getAction()}.phtml"
            );

            if (file_exists($templatePathGenerated)) {
                $route->setTemplatePath($templatePathGenerated);
            }
        }

        // And check again, now that we might have a magic template path
        if ($route->hasTemplatePath()) {
            $templatePath = $this->path->getDir($route->getTemplatePath());
            $this->view->setTemplatePath($templatePath);
            $this->view->render();
        }

        // If the callback or controller/action returned content, we need to handle it
        if ($returnContent) {
            if ($this->response->getOutput()->acceptsContent($returnContent)) {
                $this->response->setContent($returnContent);
            } else {
                $type   = gettype($returnContent);
                $output = get_class($this->response->getOutput());

                // Stop the output buffer we've started above and throw
                $this->response->stopOutputBuffer();
                throw new \Parable\Framework\Exception(
                    "Route returned value of type '{$type}', which output class '{$output}' cannot handle."
                );
            }
        }

        // Any rendered content was from before the returnContent was set, so we prepend it if there's any
        $renderedContent = $this->response->returnOutputBuffer();
        if ($renderedContent) {
            $this->response->prependContent($renderedContent);
        }

        $this->hook->trigger(self::HOOK_DISPATCH_TEMPLATE_AFTER, $route);
        $this->hook->trigger(self::HOOK_DISPATCH_AFTER, $route);
        return $this;
    }
1000463
public function route($route, $parameters = [], $status = 302, $headers = [])
    {
        $path = $this->app->make('url')->route($route, $parameters);

        return $this->to($path, $status, $headers);
    }
773786
public function createView(RouterInterface $router, $route, $params)
    {
        $view = new View();

        $view->count = $this->getNbPages();
        $view->currentPage = $this->getCurrentPage();
        $view->pages = $this->getPagerLinks($router, $route, $params);
        /** @noinspection PhpParamsInspection */
        $view->first = reset($view->pages);
        /** @noinspection PhpParamsInspection */
        $view->last = end($view->pages);
        $view->next = $this->hasNextPage() ? $view->pages[$view->currentPage + 1] : null;
        $view->prev = $this->hasPreviousPage() ? $view->pages[$view->currentPage - 1] : null;

        return $view;
    }
1026893
protected function getRouteDomain($route, &$parameters)
    {
        return $route->domain() ? $this->formatDomain($route, $parameters) : null;
    }
559258
public function execute(Request $request, Route $route, $parameters)
    {
        $request->attributes->set('_controller', $this->getControllerCallback());
        $app = Facade::getFacadeApplication();
        $controllerResolver = $app->make(ApplicationAwareControllerResolver::class);
        $callback = $controllerResolver->getController($request);
        $argumentsResolver = $app->make(ArgumentResolver::class);

        $arguments = $argumentsResolver->getArguments($request, $callback);
        $controller = $callback[0];
        $method = $callback[1];

        if (method_exists($controller, 'on_start')) {
            $controller->on_start();
        }

        if (method_exists($controller, 'runAction')) {
            $response = $controller->runAction($method, $arguments);
        } else {
            $response = call_user_func_array([$controller, $method], $arguments);
        }

        if ($response instanceof Response) {
            // note, our RedirectResponse doesn't extend Response, it extends symfony2 response
            return $response;
        }

        if ($response instanceof AbstractView) {
            $content = $response->render();
        } else if (method_exists($controller, 'getViewObject')) {
            $content = null;
            $view = $controller->getViewObject();
            if (is_object($view)) {
                $view->setController($controller);
                if (isset($view) && $view instanceof AbstractView) {
                    $content = $view->render();
                }
            }
        } else {
            $content = $response;
        }

        if (is_object($content)) {
            return $content;
        }

        $response = new Response();
        $response->setContent($content);
        return $response;
    }