本文整理汇总了PHP中Symfony\Component\Routing\Router::getContext方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getContext方法的具体用法?PHP Router::getContext怎么用?PHP Router::getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Router
的用法示例。
在下文中一共展示了Router::getContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: url
/**
* @throws \RunTimeException
* @param null|\Sonata\PageBundle\Model\PageInterface|string $page
* @param bool $absolute
* @return string
*/
public function url($page = null, $absolute = false)
{
if (!$page) {
return '';
}
$context = $this->router->getContext();
if ($page instanceof PageInterface) {
if ($page->isDynamic()) {
if ($this->environment->isDebug()) {
throw new \RunTimeException('Unable to generate path for dynamic page');
}
return '';
}
$url = $page->getCustomUrl() ?: $page->getUrl();
} else {
$url = $page;
}
$url = sprintf('%s%s', $context->getBaseUrl(), $url);
if ($absolute && $context->getHost()) {
$scheme = $context->getScheme();
$port = '';
if ('http' === $scheme && 80 != $context->getHttpPort()) {
$port = ':' . $context->getHttpPort();
} elseif ('https' === $scheme && 443 != $context->getHttpsPort()) {
$port = ':' . $context->getHttpsPort();
}
$url = $scheme . '://' . $context->getHost() . $port . $url;
}
return $url;
}
示例2: loadRoutes
public function loadRoutes($path, $options = array())
{
$filelocator = new FileLocator($path);
$routeloader = new YamlFileLoader($filelocator);
$router = new Router($routeloader, $path, $options);
$matcher = $router->getMatcher();
$routeCollection = $router->getRouteCollection();
$context = $router->getContext();
$this->dispatcher->addSubscriber(new HttpKernel\EventListener\RouterListener($matcher));
$this->shared['url.generator'] = new UrlGenerator($routeCollection, $context);
$this->router = $router;
return $router->getRouteCollection();
}
示例3: setBaseUrl
/**
* Sets the base URL.
*
* @param string $baseUrl Base URL.
*
* @return RouteRenderer
*/
public function setBaseUrl($baseUrl)
{
$this->baseUrl = '/' . trim(trim($baseUrl), '/');
$this->router->getContext()->setBaseUrl($this->baseUrl);
return $this;
}
示例4: getBaseUrl
/**
* Get curent request base url path.
*
* @param string $path path to be appended to base url
*
* @return string composed path
*/
public function getBaseUrl($path = '')
{
$context = $this->symfonyRouter->getContext();
$baseUrl = $context->getScheme() . '://' . $context->getHost() . $path;
return $baseUrl;
}